mediahost

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package mediahost validates uploads and owns the media directory.

Index

Constants

View Source
const DefaultJPEGQuality = 82

DefaultJPEGQuality is the quality renditions encode at when nothing else applies.

View Source
const DefaultMaxSize = 128 << 20

DefaultMaxSize bounds an upload when the library is not given its own cap.

View Source
const JPEGQualityKey = "media.jpeg_quality"

JPEGQualityKey names the stored quality renditions encode at.

View Source
const MaxJPEGQuality = 100

MaxJPEGQuality is the highest quality renditions may encode at.

Variables

This section is empty.

Functions

func ParseJPEGQuality added in v0.11.0

func ParseJPEGQuality(raw string) (int, error)

ParseJPEGQuality returns the quality the text names, or the reason it is not one.

func ResolveJPEGQuality added in v0.11.0

func ResolveJPEGQuality(held string, found bool) int

ResolveJPEGQuality returns the quality a stored setting names, or the default when it names none.

Types

type Config

type Config struct {
	// Dir is the directory uploads land in. Empty refuses every upload.
	Dir string
	// MaxSize bounds one upload in bytes. Zero applies [DefaultMaxSize].
	MaxSize int64
	// Settings answers the quality pictures encode at. Nil applies [DefaultJPEGQuality].
	Settings Settings
}

Config carries what a library needs to own its directory.

type Error added in v0.9.0

type Error struct {
	// Code names the rule the upload broke, for a client that translates it.
	Code string
	// Reason names the rule the upload broke, in words fit for an admin screen.
	Reason string
	// Detail is what went wrong underneath, for the log.
	Detail error
	// Meta carries the values the message the client shows names.
	Meta map[string]any
}

Error reports an upload turned away, carrying the reason an operator reads.

func (*Error) Error added in v0.9.0

func (e *Error) Error() string

Error returns the reason followed by the detail behind it.

func (*Error) Unwrap added in v0.9.0

func (e *Error) Unwrap() error

Unwrap returns the error it was raised over.

type Library

type Library struct {
	// contains filtered or unexported fields
}

Library owns the media directory uploads land in.

func New

func New(cfg Config) *Library

New returns a Library over the configured directory.

func (*Library) Cap

func (l *Library) Cap() int64

Cap returns the most bytes one upload may carry.

func (*Library) Dir

func (l *Library) Dir() string

Dir returns the directory the library owns.

func (*Library) Ingest

func (l *Library) Ingest(
	ctx context.Context, name string, data []byte, authorID uuid.UUID,
) (media.Media, error)

Ingest validates an upload, stores its files, and returns the media item they make.

func (*Library) Remove

func (l *Library) Remove(m media.Media) error

Remove deletes the item's stored file and every rendition it owns.

type Settings added in v0.11.0

type Settings interface {
	// Lookup returns the value stored under key and whether the key is set at all.
	Lookup(ctx context.Context, key string) (string, bool, error)
}

Settings answers what the site chose for the pictures it stores.

Jump to

Keyboard shortcuts

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