media

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileMediaStore

type FileMediaStore struct {
	// contains filtered or unexported fields
}

FileMediaStore is a pure in-memory implementation of MediaStore. Files are expected to already exist on disk (e.g. in /tmp/picoclaw_media/).

func NewFileMediaStore

func NewFileMediaStore() *FileMediaStore

NewFileMediaStore creates a new FileMediaStore without background cleanup.

func NewFileMediaStoreWithCleanup

func NewFileMediaStoreWithCleanup(cfg MediaCleanerConfig) *FileMediaStore

NewFileMediaStoreWithCleanup creates a FileMediaStore with TTL-based background cleanup.

func (*FileMediaStore) CleanExpired

func (s *FileMediaStore) CleanExpired() int

CleanExpired removes all entries older than MaxAge. Phase 1 (under lock): identify expired entries and remove from maps. Phase 2 (no lock): delete files from disk to minimize lock contention.

func (*FileMediaStore) ReleaseAll

func (s *FileMediaStore) ReleaseAll(scope string) error

ReleaseAll removes all files under the given scope and cleans up mappings. Phase 1 (under lock): remove entries from maps. Phase 2 (no lock): delete files from disk.

func (*FileMediaStore) Resolve

func (s *FileMediaStore) Resolve(ref string) (string, error)

Resolve returns the local path for the given ref.

func (*FileMediaStore) ResolveWithMeta

func (s *FileMediaStore) ResolveWithMeta(ref string) (string, MediaMeta, error)

ResolveWithMeta returns the local path and metadata for the given ref.

func (*FileMediaStore) Start

func (s *FileMediaStore) Start()

Start begins the background cleanup goroutine if cleanup is enabled. Safe to call multiple times; only the first call starts the goroutine.

func (*FileMediaStore) Stop

func (s *FileMediaStore) Stop()

Stop terminates the background cleanup goroutine. Safe to call multiple times; only the first call closes the channel.

func (*FileMediaStore) Store

func (s *FileMediaStore) Store(localPath string, meta MediaMeta, scope string) (string, error)

Store registers a local file under the given scope. The file must exist.

type MediaCleanerConfig

type MediaCleanerConfig struct {
	Enabled  bool
	MaxAge   time.Duration
	Interval time.Duration
}

MediaCleanerConfig configures the background TTL cleanup.

type MediaMeta

type MediaMeta struct {
	Filename    string
	ContentType string
	Source      string // "telegram", "discord", "tool:image-gen", etc.
}

MediaMeta holds metadata about a stored media file.

type MediaStore

type MediaStore interface {
	// Store registers an existing local file under the given scope.
	// Returns a ref identifier (e.g. "media://<id>").
	// Store does not move or copy the file; it only records the mapping.
	Store(localPath string, meta MediaMeta, scope string) (ref string, err error)

	// Resolve returns the local file path for a given ref.
	Resolve(ref string) (localPath string, err error)

	// ResolveWithMeta returns the local file path and metadata for a given ref.
	ResolveWithMeta(ref string) (localPath string, meta MediaMeta, err error)

	// ReleaseAll deletes all files registered under the given scope
	// and removes the mapping entries. File-not-exist errors are ignored.
	ReleaseAll(scope string) error
}

MediaStore manages the lifecycle of media files associated with processing scopes.

Jump to

Keyboard shortcuts

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