Documentation
¶
Overview ¶
Package avatar handles the two uploaded images in stackr, a user's avatar and an organization's logo, from the multipart form to the <img> tag.
Deliberately no resize or crop pipeline: browsers scale a 512px image perfectly well at the 20-40px these are rendered at, and the alternative is an image-decoding dependency plus a whole cropping UI for something nobody looks at closely. The size cap is what keeps that honest.
Index ¶
Constants ¶
const Accept = "image/png,image/jpeg,image/gif,image/webp"
Accept is the input accept attribute, kept next to the allow-list so the two can't drift.
const MaxBytes = 2 << 20 // 2 MiB
MaxBytes caps an upload. Generous for an icon, small enough that a stray RAW photo is rejected rather than stored forever.
Variables ¶
This section is empty.
Functions ¶
func Replace ¶
func Replace(ctx context.Context, fs storage.FileStorage, prefix, id, old string, fh *multipart.FileHeader) (string, error)
Replace saves a new image and deletes the one it supersedes. A failed delete is not an error, an orphaned file is a wasted inode, while a failed upload the user thinks succeeded is a bug.
func Save ¶
func Save(ctx context.Context, fs storage.FileStorage, prefix, id string, fh *multipart.FileHeader) (string, error)
Save validates and stores an uploaded image, returning its storage path. prefix separates the two kinds ("users", "orgs"); id keys the owner.
The stored name carries a random suffix so a replaced image never reuses a URL a browser has already cached.
func Serve ¶
func Serve(fs storage.FileStorage) echo.HandlerFunc
Serve streams a stored avatar. GET /avatars/*
Behind RequireAuth like every other page: these are small and not secret, but an unauthenticated endpoint that reads from a storage path is a liability nobody asked for.
Types ¶
This section is empty.