media

package
v0.98.3 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: GPL-3.0 Imports: 15 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.3

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 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.3

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 SignFile added in v0.98.3

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

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

func VerifySignedRequest added in v0.98.3

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.3

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.3

func AsAccessor(h Handler) (Accessor, bool)

AsAccessor returns Accessor when the handler implements it.

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).

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