avatar

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
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.

View Source
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

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.

func URL

func URL(storagePath string) string

URL is where a stored path is served from. Empty in, empty out, so callers can pass a possibly-unset AvatarPath straight through.

Types

This section is empty.

Jump to

Keyboard shortcuts

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