Documentation
¶
Overview ¶
Package contentref defines the reference vocabulary every ContentKit package and port shares: a tenant-scoped reference to content and the identity of a group.
Index ¶
- Variables
- func IDAt(t time.Time) string
- func LegacyID(namespace, kind string, legacyID int64, createdAt time.Time) string
- func NewID() string
- func ValidateID(id string) error
- type ContentKey
- type ContentRef
- func (r ContentRef) Content() ContentRef
- func (r ContentRef) Equal(o ContentRef) bool
- func (r ContentRef) Key() ContentKey
- func (r ContentRef) String() string
- func (r ContentRef) Validate() error
- func (r ContentRef) Version() string
- func (r ContentRef) WithVersion(contentVersionID string) ContentRef
- type GroupID
- type IDError
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidID = errors.New("contentref: content_id must be a canonical lowercase UUIDv7")
ErrInvalidID is a content id that is not a canonical UUIDv7.
Functions ¶
func IDAt ¶ added in v0.45.0
IDAt returns a UUIDv7 whose timestamp is t (millisecond precision) and whose remaining 74 bits are random, for ids generated once and stored. Imports that must derive the same id on every run use LegacyID.
func LegacyID ¶ added in v0.55.0
LegacyID is the deterministic content id of a legacy row: a UUIDv7 whose timestamp is createdAt (zero: 2010-01-01 UTC plus legacyID milliseconds) and whose other 74 bits hash "{namespace}/{kind}/{legacyID}", so re-running an import (media included) yields the same ids and folders. namespace is the host's import namespace ("doujins", "hentai0"): lowercase letters, digits, '_' or '-'; LegacyID panics on another (a host constant).
func ValidateID ¶ added in v0.45.0
ValidateID accepts only a canonical content id: 36 characters, lowercase hex, version 7, RFC 9562 variant. A content id names a media folder and a search/signal key, and is never reused: time-ordered UUIDs cannot repeat after a host's database or sequence is reset.
Types ¶
type ContentKey ¶
type ContentKey struct {
TenantID string
ContentKind string
ContentID string
ContentVersionID string
}
ContentKey is the comparable form of a ContentRef; ContentVersionID is "" for the work, which storage keys hold as NULL (internal/versionid).
func (ContentKey) Ref ¶
func (k ContentKey) Ref() ContentRef
Ref converts the key back into a reference.
type ContentRef ¶
type ContentRef struct {
TenantID string `json:"tenant_id"`
ContentKind string `json:"content_kind"`
ContentID string `json:"content_id"`
ContentVersionID *string `json:"content_version_id,omitempty"`
}
ContentRef identifies host-owned content: the work (a gallery, a video, a listing) or, when ContentVersionID is set, one selectable version of it. The host owns the meaning of ContentKind and the ids; ContentKit stores them opaquely, except that ContentID must be a canonical UUIDv7 (ValidateID). A language is never part of the reference.
func New ¶
func New(tenantID, contentKind, contentID string) ContentRef
New returns a reference to the work itself. Every ContentKit entry point validates it; Parse validates it at construction.
func NewVersion ¶
func NewVersion(tenantID, contentKind, contentID, contentVersionID string) ContentRef
NewVersion returns a reference to one version of the work.
func Parse ¶ added in v0.45.0
func Parse(tenantID, contentKind, contentID string) (ContentRef, error)
Parse returns a validated reference to the work.
func (ContentRef) Content ¶
func (r ContentRef) Content() ContentRef
Content returns the work-level reference.
func (ContentRef) Equal ¶
func (r ContentRef) Equal(o ContentRef) bool
Equal reports whether both references name the same content and version.
func (ContentRef) Key ¶
func (r ContentRef) Key() ContentKey
Key returns the comparable form used for map keys and equality.
func (ContentRef) String ¶
func (r ContentRef) String() string
func (ContentRef) Validate ¶
func (r ContentRef) Validate() error
Validate requires a tenant, kind and a UUIDv7 id (ErrInvalidID); a set version must be non-empty.
func (ContentRef) Version ¶
func (r ContentRef) Version() string
Version returns the version id, "" for the work itself.
func (ContentRef) WithVersion ¶
func (r ContentRef) WithVersion(contentVersionID string) ContentRef
WithVersion returns the reference scoped to contentVersionID ("" = the work).