Documentation
¶
Overview ¶
Package media is the workspace image library used by the composer's asset manager. Uploads are validated by their content (PNG, JPEG or GIF, decoded to read the dimensions), stored in Postgres and served publicly at /media/{id}/{file} with immutable caching, because email clients fetch them without a session. Content stores root-relative URLs; Absolutize turns them into public URLs when an email leaves ReputeCast.
Index ¶
- Constants
- func Absolutize(html, publicURL string) string
- func Inspect(data []byte) (contentType string, width, height int, alpha bool, err error)
- func Register(h huma.API, s *Service)
- func SafeFileName(name, contentType string) string
- func URL(id uuid.UUID, fileName string) string
- type ImageError
- type MediaAsset
- type MediaAssetList
- type Service
- func (s *Service) List(ctx context.Context, ws *store.Workspace, limit int) ([]MediaAsset, error)
- func (s *Service) Remove(ctx context.Context, ws *store.Workspace, id uuid.UUID) error
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) Upload(ctx context.Context, ws *store.Workspace, actor *uuid.UUID, fileName string, ...) (MediaAsset, error)
Constants ¶
const MaxBytes = 5 << 20
MaxBytes is the largest image accepted (5 MB). Email images should be far smaller; Gmail and Outlook slow down above a few hundred KB.
const MaxPixels = 100_000_000
MaxPixels guards against decompression bombs (100 megapixels).
const PathPrefix = "/media/"
PathPrefix is where images are served.
Variables ¶
This section is empty.
Functions ¶
func Absolutize ¶
Absolutize rewrites root-relative /media/ URLs in HTML to the public URL, for anything that leaves ReputeCast (sends, tests, exported HTML).
func Inspect ¶
Inspect validates image bytes by their content and returns the type, dimensions and whether the image has transparency.
func SafeFileName ¶
SafeFileName keeps a readable, URL-safe file name with the extension the content type implies.
Types ¶
type ImageError ¶
type ImageError string
ImageError is why an upload was refused, worded for the person uploading.
func (ImageError) Error ¶
func (e ImageError) Error() string
type MediaAsset ¶
type MediaAsset struct {
ID string `json:"id"`
URL string `json:"url" doc:"Root-relative URL; emails get the absolute public URL"`
FileName string `json:"fileName"`
ContentType string `json:"contentType" enum:"image/png,image/jpeg,image/gif"`
SizeBytes int `json:"sizeBytes"`
Width int `json:"width"`
Height int `json:"height"`
HasAlpha bool `json:"hasAlpha" doc:"Transparent pixels (logos survive dark mode)"`
CreatedAt time.Time `json:"createdAt"`
CreatedBy string `json:"createdBy"`
}
MediaAsset is one image in the library.
type MediaAssetList ¶
type MediaAssetList struct {
Items []MediaAsset `json:"items"`
}
MediaAssetList is the image library.
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Audit *audit.Logger
Now func() time.Time
// Static serves /media/starters/{file}: the placeholder images of the
// built-in starter templates, shipped in the binary.
Static fs.FS
// contains filtered or unexported fields
}
Service holds the media domain dependencies.
func (*Service) Remove ¶
Remove hides an image from the library. It stays reachable so emails that were already sent keep showing it.