contentref

package
v0.58.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package contentref defines the reference vocabulary every ContentKit package and port shares: a tenant-scoped reference to host-owned content and the identity of a generic taxonomy record.

Index

Constants

This section is empty.

Variables

View Source
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

func IDAt(t time.Time) string

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

func LegacyID(namespace, kind string, legacyID int64, createdAt time.Time) string

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 NewID added in v0.45.0

func NewID() string

NewID returns a new content id (a UUIDv7).

func ValidateID added in v0.45.0

func ValidateID(id string) error

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. Storage keys use the same encoding.

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).

type IDError added in v0.45.0

type IDError struct{ ID string }

IDError is a rejected content id; errors.Is(err, ErrInvalidID) holds.

func (*IDError) Error added in v0.45.0

func (e *IDError) Error() string

func (*IDError) Unwrap added in v0.45.0

func (e *IDError) Unwrap() error

type TaxonomyID

type TaxonomyID string

TaxonomyID identifies a generic ContentKit catalog record (tag, artist, series, creator, character, voice actor). Until the taxonomy module lands, taxonomy records are indexed and referenced through ContentRef with the taxonomy kind as ContentKind and the TaxonomyID as ContentID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL