Documentation
¶
Overview ¶
Package media defines an interface which must be implemented by media upload/download handlers.
Index ¶
- Constants
- func BuildSignedURL(publicBaseURL, secret, fileID string, ttl time.Duration, now time.Time) (string, error)
- func CORSHandler(req *http.Request, allowedOrigins []string, serve bool) (http.Header, int)
- func GetIdFromUrl(url, serveUrl string) types.Uid
- func ReadAll(ctx context.Context, a Accessor, fileID string) (*types.FileDef, []byte, error)
- func SignFile(secret, fileID string, exp int64) string
- func VerifySignedRequest(secret, fileID, expRaw, sig string, now time.Time) error
- type Accessor
- type Handler
- type ReadSeekCloser
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 ¶
CORSHandler is the default preflight OPTIONS processor for use by media handlers.
func GetIdFromUrl ¶
GetIdFromUrl is a helper method for extracting file ID from a URL.
func ReadAll ¶ added in v0.98.3
ReadAll opens a file by id and returns its bytes (caller must use Accessor).
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
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).
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. |
Click to show internal directories.
Click to hide internal directories.