layout

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
const (
	AreaManifest = "manifest"
	AreaPrivate  = "private"
	AreaPublic   = "public"
	AreaTemp     = "temp"
)

Folder areas.

View Source
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/"
)
View Source
const MaxDownloadName = 200

MaxDownloadName bounds a download name in bytes.

Variables

This section is empty.

Functions

func Attachment added in v0.62.0

func Attachment(name string) string

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

func CheckHosts(in map[string][]string) (map[string][]string, error)

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

func CompileDefaults(defs []Default) (map[string][]*regexp.Regexp, error)

CompileDefaults turns the name templates into anchored patterns keyed by "{ns}/{kind}".

func Disposition added in v0.62.0

func Disposition(name, contentType string) string

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

func FormatDefaults(defs []Default) string

FormatDefaults is ParseDefaults' inverse, with entries sorted by namespace and kind.

func FormatHosts added in v0.62.0

func FormatHosts(m map[string][]string) string

FormatHosts is ParseHosts' inverse, with hosts sorted.

func ParseHosts added in v0.62.0

func ParseHosts(s string) (map[string][]string, error)

ParseHosts parses "media.doujins.ai=doujins,accounts; media.hanime.media=hentai0,accounts".

func ParseSHA256Name

func ParseSHA256Name(name string) ([]byte, bool)

ParseSHA256Name returns the digest of a "sha256-{hex}" name.

func Prefix added in v0.62.0

func Prefix(namespace, kind, id string) string

Prefix is an item's folder: "{namespace}/{kind}/{id}/".

func SHA256Name added in v0.62.0

func SHA256Name(sum []byte) string

SHA256Name names a blob by its digest: "sha256-{hex}".

func ValidHashName added in v0.48.0

func ValidHashName(name string) bool

ValidHashName accepts "sha256-{64 lowercase hex}".

func ValidSegment

func ValidSegment(s string) bool

ValidSegment keeps keys stable ASCII: [A-Za-z0-9._-]{1,128}, no leading dot.

func ValidStagedName added in v0.40.0

func ValidStagedName(name string) bool

ValidStagedName accepts "u-{uuid}", a canonical lowercase UUID.

Types

type Default added in v0.62.0

type Default struct {
	Namespace, Kind string
	Names           []string
}

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

func ParseDefaults(s string) ([]Default, error)

ParseDefaults parses "doujins/gallery: cover-{w}.webp; hentai0/video: poster-{w}.webp, thumb-{w}.webp".

type Key

type Key struct {
	Namespace, Kind, ID string
	Area                string
	Name                string // the name within the area; "" for the manifest
}

Key is a parsed object key.

func Parse

func Parse(key string) (Key, bool)

Parse classifies an object key; ok is false for anything outside the layout.

Jump to

Keyboard shortcuts

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