media

package
v0.99.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package media defines an interface which must be implemented by media upload/download handlers.

Index

Constants

View Source
const (
	// SignedPathPrefix is the HTTP path prefix for HMAC-signed media downloads (FS backend).
	SignedPathPrefix = "/chatagent/media/s/"
)

Variables

This section is empty.

Functions

func BuildSignedURL added in v0.98.2

func BuildSignedURL(publicBaseURL, secret, fileID string, ttl time.Duration, now time.Time) (string, error)

BuildSignedURL builds an absolute HMAC-signed GET URL for a file id.

func CORSHandler

func CORSHandler(req *http.Request, allowedOrigins []string, serve bool) (http.Header, int)

CORSHandler is the default preflight OPTIONS processor for use by media handlers.

func FinishUpload added in v0.99.0

func FinishUpload(ctx context.Context, fd *types.FileDef, success bool, size int64) (*types.FileDef, error)

FinishUpload finalizes a file upload via the injected store.

func GetFile added in v0.99.0

func GetFile(ctx context.Context, fid string) (*types.FileDef, error)

GetFile loads file metadata via the injected store.

func GetIdFromUrl

func GetIdFromUrl(url, serveUrl string) types.Uid

GetIdFromUrl is a helper method for extracting file ID from a URL.

func ReadAll added in v0.98.2

func ReadAll(ctx context.Context, a Accessor, fileID string) (*types.FileDef, []byte, error)

ReadAll opens a file by id and returns its bytes (caller must use Accessor).

func RegisterHandler added in v0.99.0

func RegisterHandler(name string, mh Handler)

RegisterHandler saves a reference to a media upload/download handler.

func SetFileMetaStore added in v0.99.0

func SetFileMetaStore(s FileMetaStore)

SetFileMetaStore wires the persistence backend used by media handlers.

func SignFile added in v0.98.2

func SignFile(secret, fileID string, exp int64) string

SignFile returns hex HMAC-SHA256 for fileID and expiry unix timestamp.

func StartUpload added in v0.99.0

func StartUpload(ctx context.Context, fd *types.FileDef) error

StartUpload records the start of a file upload via the injected store.

func UseHandler added in v0.99.0

func UseHandler(name, mediaConfig string) error

UseHandler sets the named media handler as default and initializes it.

func VerifySignedRequest added in v0.98.2

func VerifySignedRequest(secret, fileID, expRaw, sig string, now time.Time) error

VerifySignedRequest validates exp and sig query parameters for a file id.

Types

type Accessor added in v0.98.2

type Accessor interface {
	Handler
	// SignGetURL returns a time-limited absolute URL the model provider can fetch.
	SignGetURL(ctx context.Context, fileID string, ttl time.Duration) (string, error)
	// OpenByID opens stored bytes by file id.
	OpenByID(ctx context.Context, fileID string) (*types.FileDef, ReadSeekCloser, error)
}

Accessor extends Handler with file-id based open and short-lived signed GET URLs for LLM fetch.

func AsAccessor added in v0.98.2

func AsAccessor(h Handler) (Accessor, bool)

AsAccessor returns Accessor when the handler implements it.

type FileMetaStore added in v0.99.0

type FileMetaStore interface {
	FileStartUpload(ctx context.Context, fd *types.FileDef) error
	FileFinishUpload(ctx context.Context, fd *types.FileDef, success bool, size int64) (*types.FileDef, error)
	FileGet(ctx context.Context, fid string) (*types.FileDef, error)
}

FileMetaStore persists file metadata used by media handlers.

func GetFileMetaStore added in v0.99.0

func GetFileMetaStore() FileMetaStore

GetFileMetaStore returns the injected file metadata store.

type Handler

type Handler interface {
	// Init initializes the media upload handler.
	Init(jsconf string) error

	// Headers checks if the handler wants to provide additional HTTP headers for the request.
	// It could be CORS headers, redirect to serve files from another URL, cache-control headers.
	// It returns headers as a map, HTTP status code to stop processing or 0 to continue, error.
	Headers(req *http.Request, serve bool) (http.Header, int, error)

	// Upload processes request for file upload. Returns file URL, file size, error.
	Upload(fdef *types.FileDef, file io.ReadSeeker) (string, int64, error)

	// Download processes request for file download.
	Download(url string) (*types.FileDef, ReadSeekCloser, error)

	// Delete deletes file from storage.
	Delete(locations []string) error

	// GetIdFromUrl extracts file ID from download URL.
	GetIdFromUrl(url string) types.Uid
}

Handler is an interface which must be implemented by media handlers (uploader-downloader).

var (

	// FileSystem is the active media handler after UseHandler succeeds.
	FileSystem Handler
)

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

ReadSeekCloser must be implemented by the media being downloaded.

Directories

Path Synopsis
Package fs implements github.com/flowline-io/flowbot/media interface by storing media objects in a single directory in the file system.
Package fs implements github.com/flowline-io/flowbot/media interface by storing media objects in a single directory in the file system.
Package minio implements media interface by storing media objects in Minio bucket.
Package minio implements media interface by storing media objects in Minio bucket.

Jump to

Keyboard shortcuts

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