Documentation
¶
Overview ¶
Package layout defines media object keys, dependency-free so the media gateway can classify paths without importing the media runtime:
{namespace}/{kind}/{id}/manifest.json gzip JSON; never served
/private/sha256-{hex}-{uuid} 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 BlobDigest(name string) ([]byte, bool)
- func BlobName(sum []byte, allocation string) string
- func CheckHosts(in map[string][]string) (map[string][]string, error)
- func CompileDefaults(defs []Default) (map[string]map[string]string, 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 ValidBlobName(name string) bool
- func ValidHashName(name string) bool
- func ValidPublicName(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 BlobDigest ¶ added in v0.68.0
BlobDigest separates the content digest from its canonical allocation UUID.
func BlobName ¶ added in v0.68.0
BlobName names one physical allocation of SHA-256 bytes. A later write, even of identical bytes, must receive a different allocation UUID.
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 validates and copies the exact fallback selection.
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 digest, not a physical allocation: "sha256-{hex}".
func ValidBlobName ¶
ValidBlobName accepts only the current private allocation layout.
func ValidHashName ¶ added in v0.48.0
ValidHashName accepts "sha256-{64 lowercase hex}".
func ValidPublicName ¶ added in v0.68.0
ValidPublicName also accepts the generation suffix on a logical public filename. Only object names gain that allowance; folder segments keep their existing bounds. Default images use content-addressed names.
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
type Default struct {
Namespace, Kind string
Files map[string]string // logical name -> sha256-{digest}.webp
}
Default maps logical public names to immutable rendered default objects. The gateway uses this deployment-owned selection only when an item is missing.
func ParseDefaults ¶ added in v0.62.0
ParseDefaults parses "doujins/gallery: cover-460.webp=sha256-{digest}.webp".