mediahost

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package mediahost validates uploads and owns the media directory.

Index

Constants

View Source
const DefaultMaxSize = 128 << 20

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

Variables

This section is empty.

Functions

This section is empty.

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
}

Config carries what a library needs to own its directory.

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(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 Refusal

type Refusal 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
}

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

func (*Refusal) Error

func (r *Refusal) Error() string

Error returns the reason followed by the detail behind it.

func (*Refusal) Unwrap

func (r *Refusal) Unwrap() error

Unwrap returns the error the refusal was raised over.

Jump to

Keyboard shortcuts

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