mediacache

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultInboundMediaMaxBytes int64 = 128 * 1024 * 1024

Inbound media cap applied when gateway.max_inbound_media_bytes is absent or unparseable

View Source
const MediaCacheMaxAgeHours = 24

Age in hours past which the cleanup sweeps delete cached media

Variables

View Source
var ContainerToExt = map[string]string{
	"m4a": ".m4a", "mp4": ".mp4", "ogg": ".ogg", "flac": ".flac", "wav": ".wav", "mp3": ".mp3", "aac": ".aac", "webm": ".webm",
}

Container id to canonical file extension

View Source
var SupportedDocumentTypes = map[string]string{
	".pdf": "application/pdf", ".md": "text/markdown", ".txt": "text/plain", ".csv": "text/csv",
	".log": "text/plain", ".json": "application/json", ".xml": "application/xml",
	".yaml": "application/yaml", ".yml": "application/yaml", ".toml": "application/toml",
	".ini": "text/plain", ".cfg": "text/plain", ".zip": "application/zip",
	".doc": "application/msword", ".xls": "application/vnd.ms-excel",
	".ppt":  "application/vnd.ms-powerpoint",
	".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
	".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
	".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
	".ts":   "text/plain", ".py": "text/plain", ".sh": "text/plain",
}

Document extensions the gateway accepts with their MIME types

View Source
var SupportedVideoTypes = map[string]string{
	".mp4": "video/mp4", ".mov": "video/quicktime", ".webm": "video/webm", ".mkv": "video/x-matroska", ".avi": "video/x-msvideo",
}

Video extensions the gateway accepts with their MIME types

Functions

func AudioCacheDir

func AudioCacheDir(ctx context.Context, h string) (string, error)

Audio cache directory of the home, created on demand

func CacheAudioFromBytes

func CacheAudioFromBytes(ctx context.Context, h string, data []byte, ext string) (string, error)

Caches audio bytes under the container sniffed extension and returns the path

func CacheDocumentFromBytes

func CacheDocumentFromBytes(ctx context.Context, h string, data []byte, filename string) (string, error)

Caches document bytes as doc_uuid12_name with the name sanitized, refusing a path that leaves the cache

func CacheImageFromBytes

func CacheImageFromBytes(ctx context.Context, h string, data []byte, ext string) (string, error)

Caches image bytes and returns the path, refusing oversized payloads and bytes that are not an image

func CacheVideoFromBytes

func CacheVideoFromBytes(ctx context.Context, h string, data []byte, ext string) (string, error)

Caches video bytes and returns the path, refusing oversized payloads

func CleanupAudioCache

func CleanupAudioCache(ctx context.Context, h string, maxAgeHours float64) (int, error)

Deletes cached audio older than the age in hours and returns the count

func CleanupDocumentCache

func CleanupDocumentCache(ctx context.Context, h string, maxAgeHours float64) (int, error)

Deletes cached documents older than the age in hours and returns the count

func CleanupImageCache

func CleanupImageCache(ctx context.Context, h string, maxAgeHours float64) (int, error)

Deletes cached images older than the age in hours and returns the count

func CleanupScreenshotCache

func CleanupScreenshotCache(ctx context.Context, h string, maxAgeHours float64) (int, error)

Deletes cached screenshots older than the age in hours and returns the count

func CleanupVideoCache

func CleanupVideoCache(ctx context.Context, h string, maxAgeHours float64) (int, error)

Deletes cached videos older than the age in hours and returns the count

func DocumentCacheDir

func DocumentCacheDir(ctx context.Context, h string) (string, error)

Document cache directory of the home, created on demand

func ImageCacheDir

func ImageCacheDir(ctx context.Context, h string) (string, error)

Image cache directory of the home, created on demand

func InboundMediaMaxBytes

func InboundMediaMaxBytes(ctx context.Context, h string) int64

Inbound media byte cap from the home config, the default when the key is missing or not an integer

func SniffAudioExt

func SniffAudioExt(data []byte, fallbackExt string) string

Container matching extension with generic MP4 claimed as m4a, the dotted fallback when unknown

func SniffContainer

func SniffContainer(data []byte) (string, bool)

Container key from magic bytes, false when the bytes match no audio or AV container

func TranscodeToOggOpus

func TranscodeToOggOpus(ctx context.Context, path, bitrate string, timeout time.Duration, outputPath string) (string, error)

Encodes the file to voip tuned Ogg Opus through ffmpeg, empty when ffmpeg is missing or the encode fails

func ValidateInboundMediaSize

func ValidateInboundMediaSize(ctx context.Context, h string, size int64, mediaType string, maxBytes *int64) error

Rejects a payload over the cap, nil maxBytes reading the home config and a zero cap disabling the check

func VideoCacheDir

func VideoCacheDir(ctx context.Context, h string) (string, error)

Video cache directory of the home, created on demand

Types

type ValueError

type ValueError struct{ Msg string }

Error the Python cache functions raise as ValueError

func (*ValueError) Error

func (e *ValueError) Error() string

func (*ValueError) PyTypeName

func (e *ValueError) PyTypeName() string

Python exception class name the error stands for

Jump to

Keyboard shortcuts

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