media

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const TempDirName = "picoclaw_media"

Variables

This section is empty.

Functions

func TempDir added in v0.2.4

func TempDir() string

TempDir returns the shared temporary directory used for downloaded media.

Types

type CleanupPolicy added in v0.2.4

type CleanupPolicy string

CleanupPolicy controls how the MediaStore treats the underlying file when a ref is released or expires.

const (
	// CleanupPolicyDeleteOnCleanup means the file is store-managed and may be
	// deleted once the final ref for that path is gone.
	CleanupPolicyDeleteOnCleanup CleanupPolicy = "delete_on_cleanup"
	// CleanupPolicyForgetOnly means the store should only drop ref mappings and
	// must never delete the underlying file.
	CleanupPolicyForgetOnly CleanupPolicy = "forget_only"
)

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 store-managed 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 store-managed files from disk once their final path ref is gone.

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.
	CleanupPolicy CleanupPolicy // defaults to CleanupPolicyDeleteOnCleanup
}

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.
	// If meta.CleanupPolicy is empty, CleanupPolicyDeleteOnCleanup is assumed.
	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