Documentation
¶
Overview ¶
Package mediahost validates uploads and owns the media directory.
Index ¶
- Constants
- func ParseJPEGQuality(raw string) (int, error)
- func ResolveJPEGQuality(held string, found bool) int
- type Config
- type Error
- type Library
- func (l *Library) Cap() int64
- func (l *Library) Dir() string
- func (l *Library) Finish(m media.Media)
- func (l *Library) Ingest(ctx context.Context, name string, data []byte, authorID uuid.UUID) (media.Media, error)
- func (l *Library) Recover(ctx context.Context, before time.Time, saved Saved) ([]string, error)
- func (l *Library) Remove(m media.Media) error
- type Saved
- type Settings
Constants ¶
const DefaultConcurrentImages = 2
DefaultConcurrentImages is how many images decode and resize at once when the library is not given its own limit.
const DefaultJPEGQuality = 82
DefaultJPEGQuality is the quality sub-sizes encode at when nothing else applies.
const DefaultMaxSize = 128 << 20
DefaultMaxSize bounds an upload when the library is not given its own cap.
const JPEGQualityKey = "media.jpeg_quality"
JPEGQualityKey names the stored quality sub-sizes encode at.
const MaxConcurrentImages = 64
MaxConcurrentImages is the most images a site may let decode and resize at once.
const MaxJPEGQuality = 100
MaxJPEGQuality is the highest quality sub-sizes may encode at.
Variables ¶
This section is empty.
Functions ¶
func ParseJPEGQuality ¶ added in v0.11.0
ParseJPEGQuality returns the quality the text names, or the reason it is not one.
func ResolveJPEGQuality ¶ added in v0.11.0
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
// ConcurrentImages bounds how many images decode and resize at once. Zero applies [DefaultConcurrentImages].
ConcurrentImages int
}
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.
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library owns the media directory uploads land in.
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.