Documentation
¶
Overview ¶
Package layout defines media object keys, dependency-free so the access agent can classify paths without importing the media runtime:
{namespace}/{kind}/{id}/manifest.json gzip JSON; never served
/private/sha256-{hex} every blob: uploads, derived files, editor views
/public/{name} app-declared names, e.g. cover-460.webp
/temp/{name} in-flight writes and staged uploads (u-{uuid}); never served
{namespace}/{kind}/_default/public/{name} a public preset's default image
The URL of an object is its key under /v1/ on the site's media host.
Index ¶
- Constants
- func Attachment(name string) string
- func CheckHosts(in map[string][]string) (map[string][]string, error)
- func CompileDefaults(defs []Default) (map[string][]*regexp.Regexp, error)
- func Disposition(name, contentType string) string
- func FormatDefaults(defs []Default) string
- func FormatHosts(m map[string][]string) string
- func ParseHosts(s string) (map[string][]string, error)
- func ParseSHA256Name(name string) ([]byte, bool)
- func Prefix(namespace, kind, id string) string
- func SHA256Name(sum []byte) string
- func ValidHashName(name string) bool
- func ValidSegment(s string) bool
- func ValidStagedName(name string) bool
- type Default
- type Key
Constants ¶
const ( AreaManifest = "manifest" AreaPrivate = "private" AreaPublic = "public" AreaTemp = "temp" )
Folder areas.
const ( // ManifestName is the manifest's key within the folder. ManifestName = "manifest.json" // DefaultID is the item id under which a kind's default public images live. DefaultID = "_default" // SHA256Prefix starts every blob name. SHA256Prefix = "sha256-" // StagedPrefix starts a staged upload's name in temp/. StagedPrefix = "u-" // URLPrefix is the path every media URL starts with. URLPrefix = "/v1/" )
const MaxDownloadName = 200
MaxDownloadName bounds a download name in bytes.
Variables ¶
This section is empty.
Functions ¶
func Attachment ¶ added in v0.62.0
Attachment is the Content-Disposition for a download name: an ASCII fallback plus the RFC 5987 UTF-8 name.
func CheckHosts ¶ added in v0.62.0
CheckHosts validates a host map: lower-case names without a port, each with valid namespaces. It returns a copy.
func CompileDefaults ¶ added in v0.62.0
CompileDefaults turns the name templates into anchored patterns keyed by "{ns}/{kind}".
func Disposition ¶ added in v0.62.0
Disposition is the Content-Disposition of a download requested as name (the URL's unsigned dl) for an object of contentType: always an attachment. The name is used only when it is plain (no path separator, control character or bidirectional format character, at most MaxDownloadName bytes) and ends in an extension of the object's type, so a link cannot rename a file into another type, or make it read as one.
func FormatDefaults ¶ added in v0.62.0
FormatDefaults is ParseDefaults' inverse, with entries sorted by namespace and kind.
func FormatHosts ¶ added in v0.62.0
FormatHosts is ParseHosts' inverse, with hosts sorted.
func ParseHosts ¶ added in v0.62.0
ParseHosts parses "media.doujins.ai=doujins,accounts; media.hanime.media=hentai0,accounts".
func ParseSHA256Name ¶
ParseSHA256Name returns the digest of a "sha256-{hex}" name.
func SHA256Name ¶ added in v0.62.0
SHA256Name names a blob by its digest: "sha256-{hex}".
func ValidHashName ¶ added in v0.48.0
ValidHashName accepts "sha256-{64 lowercase hex}".
func ValidSegment ¶
ValidSegment keeps keys stable ASCII: [A-Za-z0-9._-]{1,128}, no leading dot.
func ValidStagedName ¶ added in v0.40.0
ValidStagedName accepts "u-{uuid}", a canonical lowercase UUID.
Types ¶
type Default ¶ added in v0.62.0
Default declares the public names of {Namespace}/{Kind} that fall back to {Namespace}/{Kind}/_default/public/{name} when an item's object is missing: templates over [A-Za-z0-9._-] with {w} (digits) and {name} placeholders, e.g. "cover-{w}.webp". The access agent serves them; the registry derives them (media.AgentConfig).
func ParseDefaults ¶ added in v0.62.0
ParseDefaults parses "doujins/gallery: cover-{w}.webp; hentai0/video: poster-{w}.webp, thumb-{w}.webp".