Documentation
¶
Index ¶
- Constants
- Variables
- func MimeFromPath(filePath string) string
- func ReadAllWithLimit(reader io.Reader, maxBytes int64) ([]byte, error)
- type Asset
- type IngestInput
- type MediaType
- type Service
- func (s *Service) AccessPath(ctx context.Context, asset Asset) string
- func (s *Service) EnsureAccessPath(ctx context.Context, asset Asset) (string, error)
- func (s *Service) GetByStorageKey(ctx context.Context, botID, storageKey string) (Asset, error)
- func (s *Service) Ingest(ctx context.Context, input IngestInput) (Asset, error)
- func (s *Service) IngestContainerFile(ctx context.Context, botID, containerPath string) (Asset, error)
- func (s *Service) IngestWorkspaceFile(ctx context.Context, botID, containerPath string) (Asset, error)
- func (s *Service) Open(ctx context.Context, botID, contentHash string) (io.ReadCloser, Asset, error)
- func (s *Service) Resolve(ctx context.Context, botID, contentHash string) (Asset, error)
- func (s *Service) Stat(ctx context.Context, botID, contentHash string) (Asset, error)
Constants ¶
const ( // MaxAssetBytes is the global max accepted payload size. MaxAssetBytes int64 = 200 * 1024 * 1024 )
Variables ¶
var ( // ErrAssetNotFound indicates the requested media asset does not exist. ErrAssetNotFound = errors.New("media asset not found") ErrProviderUnavailable = errors.New("storage provider unavailable") // ErrAssetTooLarge indicates the payload exceeds the configured max asset size. ErrAssetTooLarge = errors.New("media asset too large") // ErrPathTraversal indicates a storage key attempted directory traversal. ErrPathTraversal = errors.New("path traversal is forbidden") )
Functions ¶
func MimeFromPath ¶
MimeFromPath derives MIME from an already-persisted filename or storage key. It is deliberately metadata-only: history reads can use it without opening workspace storage or waking a runtime provider.
Types ¶
type Asset ¶
type Asset struct {
ContentHash string `json:"content_hash"`
BotID string `json:"bot_id"`
Mime string `json:"mime"`
SizeBytes int64 `json:"size_bytes"`
StorageKey string `json:"storage_key"`
}
Asset is the domain representation of a persisted media object. ContentHash is the content-addressed identifier (SHA-256 hex).
type IngestInput ¶
type IngestInput struct {
BotID string
Mime string
// Reader provides the raw bytes; caller is responsible for closing.
Reader io.Reader
// MaxBytes optionally overrides the default size limit.
MaxBytes int64
// OriginalExt preserves the source file extension (e.g. ".md") so it
// survives even when the MIME type is unknown / generic.
OriginalExt string
}
IngestInput carries the data needed to persist a new media asset.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides content-addressed media asset persistence. All metadata is derived from the filesystem — no database, no sidecar files.
func NewService ¶
NewService creates a media service with the given storage provider.
func (*Service) AccessPath ¶
AccessPath returns a reachable consumer reference for a persisted asset. Providers that support materialization may promote spill storage into their consumer-addressable primary store. Errors are intentionally collapsed for legacy callers; new routing code should use EnsureAccessPath.
func (*Service) EnsureAccessPath ¶
EnsureAccessPath returns a consumer-visible path, materializing the asset into addressable storage when the provider supports it.
func (*Service) GetByStorageKey ¶
GetByStorageKey returns an asset derived from a known storage key.
func (*Service) Ingest ¶
Ingest persists a new media asset. It hashes the content, deduplicates by checking the filesystem, and stores the bytes. Returns a derived Asset.
func (*Service) IngestContainerFile ¶
func (s *Service) IngestContainerFile(ctx context.Context, botID, containerPath string) (Asset, error)
IngestContainerFile reads an arbitrary file from a bot's /data/ directory and ingests it into the media store. The provider must implement ContainerFileOpener.
func (*Service) IngestWorkspaceFile ¶ added in v1.0.0
func (s *Service) IngestWorkspaceFile(ctx context.Context, botID, containerPath string) (Asset, error)
IngestWorkspaceFile archives a file below /data that a model referenced in Markdown. It reads the file the same way the workspace file manager does.
func (*Service) Open ¶
func (s *Service) Open(ctx context.Context, botID, contentHash string) (io.ReadCloser, Asset, error)
Open returns a reader for the media asset identified by content hash. It locates the file by scanning extensions under the hash prefix and derives MIME from the extension.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package lottie rasterises Lottie animations — Telegram animated stickers in particular — without cgo, a native library or a helper process.
|
Package lottie rasterises Lottie animations — Telegram animated stickers in particular — without cgo, a native library or a helper process. |