storage

package
v3.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountFolder

func AccountFolder(accountID string) string

AccountFolder returns the folder every one of an account's objects sits under: accounts/<accountID>. Erasing the account is a delete of everything below it, so the prefix has to be built in one place. Validate accountID before calling it.

func AccountPrefix

func AccountPrefix(accountID string) string

AccountPrefix is AccountFolder with the trailing slash a bucket listing needs, so accounts/acct-1/ never matches accounts/acct-10/.

func GenerateObjectKey

func GenerateObjectKey(prefix, originalName string) string

GenerateObjectKey produces a unique object key by prepending a KSUID to the sanitized original filename under the given prefix.

func GenerateObjectKeyWithID

func GenerateObjectKeyWithID(prefix, originalName string) (id, key string)

GenerateObjectKeyWithID is like GenerateObjectKey but also returns the bare KSUID so callers can use a consistent ID across all backends.

func NewComposite

func NewComposite(
	primary services.FileService,
	secondaries []services.FileService,
	logger entities.Logger,
) services.FileService

NewComposite creates a FileService that fans out uploads to a primary and zero or more secondary backends. A single ID is pre-generated and shared across all backends so replicas are correlated. The result from the first secondary that succeeds is returned (providing an app-hosted URL). When secondaries are configured and every one fails, the upload fails: the primary's URL points straight at the bucket, where no account check runs. With no secondaries the primary result is returned. Upload data is spooled to a temporary file to avoid holding the entire body in memory.

func ObjectKey

func ObjectKey(accountID, id, safeName string) string

ObjectKey returns the key an upload is stored under: accounts/<accountID>/uploads/<id>-<safeName>. The account prefix is the upload's ownership record, which the read route checks. Validate accountID and id, and sanitize the name, before calling it.

func SanitizeFilename

func SanitizeFilename(name string) string

SanitizeFilename strips path separators, collapses unsafe characters, and truncates the result to a safe length.

func ValidateAccountID

func ValidateAccountID(accountID string) error

ValidateAccountID checks that an account ID is non-empty and holds only alphanumerics, underscores and hyphens — the rule the per-account knowledge graph store applies to the same ids — so it cannot climb out of the account's folder once it is part of a path or object key.

func ValidateID

func ValidateID(id string) error

ValidateID checks that a caller-supplied ID contains only safe characters (alphanumeric, underscore, hyphen) and is non-empty. This prevents path traversal when the ID is used as part of a filesystem path or object key.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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