Documentation
¶
Overview ¶
Package avatars owns avatar resolution for shithub user profiles. S09 ships the deterministic SVG identicon (rendered server-side, no upload needed) plus the routing skeleton for serving uploaded avatars from object storage. Real upload (resize / EXIF-strip) lands in S10.
Index ¶
Constants ¶
const IdenticonSize = 5
IdenticonSize is the SVG viewBox side length. The image is square and renders at any CSS px size via width/height attributes.
const MaxPixelArea = 24 * 1000 * 1000
MaxPixelArea bounds the *decoded* image's pixel area as a defense-in-depth check against decompression-bomb attacks: a small file (well under MaxUploadBytes) can decode to a huge image. We reject anything past 24 megapixels (e.g. 4900×4900), well above any reasonable avatar source.
const MaxUploadBytes = 5 * 1024 * 1024 // 5 MiB
MaxUploadBytes caps how big an uploaded avatar may be before decoding. Stops trivially large uploads from soaking RAM during decode.
Variables ¶
var ( ErrTooLarge = errors.New("avatars: upload exceeds size limit") ErrUnsupported = errors.New("avatars: unsupported image format") ErrDecompression = errors.New("avatars: image dimensions exceed limit") ErrDecode = errors.New("avatars: could not decode image") )
Errors surfaced to the handler. Each maps to a friendly UI message.
var VariantSizes = []int{460, 200, 40}
VariantSizes is the set of resize targets we generate per upload. The largest is what the public avatar route serves; smaller ones are kept so a future "/avatars/:user/:size" route can serve them without re-resizing.
Functions ¶
func Identicon ¶
Identicon returns an inline SVG identicon for username. Same input → same output (deterministic). The SVG carries width/height attributes so it can be embedded as inline markup OR served as a standalone file.
The pattern is a 5×5 grid mirrored horizontally — left two columns are mirrored to the right, the middle column is independent. Each cell is colored if the corresponding bit in the digest is 1.
Types ¶
type Variant ¶
Variant is one rendered output: a sized PNG ready for upload to the object store.
func Process ¶
Process reads an uploaded image, validates it, and produces resized PNG variants. It strips EXIF as a side effect of re-encoding.
Returns the variants in VariantSizes order plus a content-addressed key component (sha256 of the largest variant's bytes) the caller can embed in the storage path.