feat(public): serve sponsor/track logos as cacheable URLs, downscale uploads - #15
Merged
Merged
Conversation
…le uploads
- add keyless GET /v1/public/{sponsors,tracks}/{id}/logo returning raw
image bytes with ETag and versioned immutable Cache-Control
- public list responses now return logo_url instead of inline
logo_data/logo_content_type
- portal downscales logos to <=512px WebP on upload
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Public consumers (zero-day site) currently receive every sponsor/track logo as inline base64 in the list JSON and end up inlining
data:URIs into HTML — no browser/CDN caching, no resizing, multi-MB page HTML. This PR keeps HARP as the content source but moves logo bytes out of the JSON.Backend —
cmd/api/public.go,cmd/api/api.goGET /v1/public/sponsorsandGET /v1/public/tracksnow returnPublicSponsor/PublicTrackDTOs:logo_data+logo_content_typeare replaced by/v1/sponsors,/v1/tracks) are unchanged and still returnlogo_data.GET /v1/public/sponsors/{sponsorID}/logoandGET /v1/public/tracks/{trackID}/logo(mounted outsideAPIKeyMiddlewareso the URL works in<img>/next/image). They decode the stored base64 and respond with the storedContent-Type,ETag: "{updated_at unix}",X-Content-Type-Options: nosniff, and honorIf-None-Match→ 304.Cache-Control: public, max-age=31536000, immutableonly when?vmatches the current version; otherwisepublic, max-age=300. A new upload bumpsupdated_at, so the list emits a new URL and old ones can be cached forever without a stale-logo risk.docs/docs.go).Portal —
client/portal/src/shared/lib/logo-image.tsprepareLogoForUpload(file)decodes viacreateImageBitmap(fallback<img>), draws to a canvas capped at 512px on the longest side, encodes WebP q=0.85 (PNG fallback if the browser can't encode WebP), keeps the original bytes if re-encoding wouldn't shrink an already-small image. Transparency preserved; animated GIFs flatten to the first frame.uploadLogonow go through it (covers both form dialog and table quick-upload). The file-picker limit was raised to a 10MB source cap (MAX_LOGO_SOURCE_BYTES); the backend decoded caps (1MB / 750KB) are still enforced post-compression in the store with a toast.pages/admin/sponsors/constants.tsto mirror tracks.Consumer follow-up: zero-day-2026 needs to switch from
logo_datatologo_url(companion PR).Tests:
cmd/api/public_logos_test.gocovers list shape (nologo_data, correctlogo_url), keyless image serving, immutable vs. non-immutable cache headers, ETag/304, 404s, 500.go test ./cmd/api/,go vet,gofmt, portallint/format:check/buildall pass.Link to Devin session: https://app.devin.ai/sessions/919a1d99cd6c4f7d9452edb8a04fe394
Open in Devin Desktop: https://app.devin.ai/desktop/session/919a1d99cd6c4f7d9452edb8a04fe394?variant=devin
Requested by: @balebbae