Documentation
¶
Index ¶
- func AccountFolder(accountID string) string
- func AccountPrefix(accountID string) string
- func GenerateObjectKey(prefix, originalName string) string
- func GenerateObjectKeyWithID(prefix, originalName string) (id, key string)
- func NewComposite(primary services.FileService, secondaries []services.FileService, ...) services.FileService
- func ObjectKey(accountID, id, safeName string) string
- func SanitizeFilename(name string) string
- func ValidateAccountID(accountID string) error
- func ValidateID(id string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccountFolder ¶
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 ¶
AccountPrefix is AccountFolder with the trailing slash a bucket listing needs, so accounts/acct-1/ never matches accounts/acct-10/.
func GenerateObjectKey ¶
GenerateObjectKey produces a unique object key by prepending a KSUID to the sanitized original filename under the given prefix.
func GenerateObjectKeyWithID ¶
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 ¶
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 ¶
SanitizeFilename strips path separators, collapses unsafe characters, and truncates the result to a safe length.
func ValidateAccountID ¶
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 ¶
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.