attach

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package attach ingests uploaded images and videos: it sniffs the real content type, optionally optimizes images (EXIF-orient, downscale, re-encode to lossy WebP, keep-smaller), and returns the bytes to persist plus metadata. It never touches the filesystem, so it is pure and easily tested; the caller writes the returned bytes through the store.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported = errors.New("unsupported file type")
	ErrTooLarge    = errors.New("image is too large (over 50 megapixels)")
	ErrDecode      = errors.New("could not decode image")
)

Errors surfaced to HTTP handlers.

Functions

func Sniff

func Sniff(data []byte) (mime, kind, ext string, ok bool)

Sniff detects an uploaded file's real type from its magic bytes (never the client-provided extension or MIME). It returns the canonical MIME, coarse kind ("image"/"video"), a normalized extension, and whether the type is supported.

Types

type Config

type Config struct {
	Optimize     bool
	MaxDimension int
	Quality      int
	MaxVideoMB   int
}

Config controls optimization, derived from config.json's attachments block.

func FromConfig

func FromConfig(a config.Attachments) Config

FromConfig adapts the persisted attachments config.

type Processed

type Processed struct {
	FileName      string
	Data          []byte
	Mime          string
	Kind          string // image | video
	OriginalBytes int64
	FinalBytes    int64
	Width         int
	Height        int
	Optimized     bool
	Warning       string
}

Processed is the outcome of ingesting one file.

func Process

func Process(clientName string, data []byte, cfg Config) (Processed, error)

Process ingests one file. clientName seeds the filename; empty names (pasted blobs) become "paste". The returned FileName is content-addressed so the same bytes always map to the same name (free dedup).

Jump to

Keyboard shortcuts

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