Give uploads one path end to end, and serve /uploads/ from Garage first
Frontend: src/uploads.js is the one way to store or show a file (uploadFile, ACCEPT, kindOf, isUploadUrl, tagFor, mediaSize). Chat, the box editor, canvas drops and the background editor all use it; views/home3/upload.js and the chat store's own axios call are gone. Backend: POST /api/uploads (was /messages/upload) is a thin wrapper over services.Uploads.Save, which owns validation, naming and storage. The three per-extension maps are now one UploadTypes table, and a refused file is an *UploadError whose message is safe to show. nginx now fetches /uploads/ from Garage first and falls back to the volume on a 404 or any 5xx, so the bucket is the source of truth and deleting a file in garage-webui unpublishes it, while a Garage outage still only affects bucket-only files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+11
-7
@@ -172,7 +172,7 @@ for the things GraphQL cannot do:
|
||||
| --- | --- |
|
||||
| `/auth/*` | cookie handling and the status-code-only admin probe |
|
||||
| `/spotify/callback` | OAuth providers redirect a *browser* here |
|
||||
| `/messages/upload`, `/radio/upload`, `/rowing` (POST) | multipart file uploads |
|
||||
| `/uploads`, `/radio/upload`, `/rowing` (POST) | multipart file uploads |
|
||||
| `/notes/*path` | streams a file download, not JSON |
|
||||
| `/ws` | WebSocket upgrade |
|
||||
| `/rowing` (GET), `/spotify/listening`, `/spotify/recent` | predate the equivalent queries; kept working |
|
||||
@@ -226,12 +226,16 @@ dormant, which is why callers nil-check `Store.SpotifyClient` and friends.
|
||||
(Steam).
|
||||
- **python_call.go** — `CallPython`, the one way to reach the Python service's
|
||||
internal routes. See [Calling the Python service](#calling-the-python-service).
|
||||
- **file_store.go** — where public uploads are written. `NewUploadStore`
|
||||
returns the disk store (`/backend/uploads/`) when `S3_ENDPOINT` is unset,
|
||||
and otherwise the Garage bucket wrapped in `FallbackFileStore`, which logs
|
||||
a failed S3 write and retries on disk. nginx serves `/uploads/` from disk
|
||||
first and the bucket second, so either store's files work at the same URL.
|
||||
Private attachments always stay on disk (nginx cannot gate a bucket).
|
||||
- **uploads.go** — every stored file. `Uploads.Save(ctx, fileHeader, private)`
|
||||
validates against `UploadTypes` (extension, stored Content-Type, content
|
||||
sniff) and `MaxUploadSize`, names the file randomly, stores it and returns
|
||||
its `/uploads/...` URL; an `*UploadError` is the uploader's fault and safe
|
||||
to show them. Public files go to the Garage bucket wrapped in
|
||||
`FallbackFileStore` (a failed S3 write is logged and retried on disk), or
|
||||
to disk alone when `S3_ENDPOINT` is unset; private ones always to disk
|
||||
(nginx cannot gate a bucket). nginx serves `/uploads/` from the bucket
|
||||
first and disk second, so either store's files work at the same URL. A new
|
||||
handler that takes a file calls `store.Uploads.Save`.
|
||||
- **notes.go** — path-traversal-safe file lookup for the notes directory.
|
||||
- **seed.go** — dev-only test data. Creates an admin with the password
|
||||
`password`, so it must never run in production (`SEED_DB=true` is set only
|
||||
|
||||
Reference in New Issue
Block a user