Give uploads one path end to end, and serve /uploads/ from Garage first
Test and deploy / deploy (push) Successful in 3m48s
Test and deploy / test (push) Successful in 37s

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:
2026-10-15 21:04:37 +01:00
co-authored by Claude Opus 5.5
parent 422cde4708
commit 65fddfcfa2
26 changed files with 848 additions and 668 deletions
+31 -24
View File
@@ -298,37 +298,44 @@ http {
# as downloads, and the locked-down CSP means even an uploaded .html
# can run no script and load no resource.
#
# TWO PLACES, DISK FIRST. A file is looked for on the shared `uploads`
# volume and, only if it is not there, fetched from the Garage bucket
# (@uploads_bucket). Disk first is deliberate: everything uploaded
# before Garage, and anything the backend wrote to disk because Garage
# refused it (services/file_store.go), is served exactly as before
# with Garage not involved at all — Garage being down can only affect
# files that exist nowhere else. The cost is shadowing: a file present
# in both is served from disk, so deleting it in the bucket alone does
# nothing until the disk copy goes too.
# `root /` rather than `alias`: the volume is mounted at /uploads, so
# the URI already is the path, and try_files is unreliable with alias.
# GARAGE FIRST, DISK SECOND. /uploads/<name> is fetched from the
# Garage bucket's website endpoint, which serves the bucket
# anonymously and picks it by the Host header (garage/garage.toml:
# s3_web); the bucket is reachable only over app-network, so this is
# the only public way in. If Garage has no such file, or is down, the
# request falls through to the shared `uploads` volume
# (@uploads_disk), which holds uploads from before Garage and anything
# the backend wrote there because Garage refused it
# (backend/services/uploads.go). So the bucket is the source of truth
# — deleting a file in garage-webui unpublishes it unless a disk copy
# exists — while a Garage outage only costs files that are nowhere
# else.
# proxy_connect_timeout 2s - Garage is on the same bridge network,
# so a slow connect means it is down; fall back quickly rather
# than after the 60s default.
# proxy_intercept_errors + error_page - Garage's 404 and any 5xx
# (including nginx's own 502 when the garage container doesn't
# exist) become a look at the disk instead.
# Range requests pass through either way, so video seeks.
# @uploads_disk sees the URI after the rewrite (/<name>), hence
# `root /uploads`. The headers are repeated, not inherited: a named
# location is its own location.
location /uploads/ {
root /;
try_files $uri @uploads_bucket;
rewrite ^/uploads/(.*)$ /$1 break;
proxy_pass $upstream_garage_web;
proxy_set_header Host uploads.web.garage;
proxy_connect_timeout 2s;
proxy_intercept_errors on;
error_page 404 500 502 503 504 = @uploads_disk;
include /etc/nginx/security_headers.conf;
add_header X-Content-Type-Options nosniff always;
add_header Content-Disposition "inline" always;
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
}
# Garage's website endpoint, which serves the bucket anonymously and
# picks it from the Host header (garage/garage.toml: s3_web). The
# bucket is reachable only over app-network, so this location is the
# only public way in. Range requests pass through, so video seeks.
# The headers are repeated, not inherited: a named location is its own
# location. If the garage container is absent the variable upstream
# fails per request (502) — nginx itself still starts.
location @uploads_bucket {
rewrite ^/uploads/(.*)$ /$1 break;
proxy_pass $upstream_garage_web;
proxy_set_header Host uploads.web.garage;
location @uploads_disk {
root /uploads;
try_files $uri =404;
include /etc/nginx/security_headers.conf;
add_header X-Content-Type-Options nosniff always;
add_header Content-Disposition "inline" always;
+10 -7
View File
@@ -47,24 +47,27 @@
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
}
# The /uploads/ blocks (and @uploads_bucket) are the production ones MINUS
# The /uploads/ blocks (and @uploads_disk) are the production ones MINUS
# `include security_headers.conf`: that file carries HSTS, which must
# never be sent from localhost. That one line is why they are not in
# the shared route table (see WHAT DOES NOT in
# nginx_routes.conf.template). Keep the rest in step with
# nginx.conf.template.
location /uploads/ {
root /;
try_files $uri @uploads_bucket;
rewrite ^/uploads/(.*)$ /$1 break;
proxy_pass $upstream_garage_web;
proxy_set_header Host uploads.web.garage;
proxy_connect_timeout 2s;
proxy_intercept_errors on;
error_page 404 500 502 503 504 = @uploads_disk;
add_header X-Content-Type-Options nosniff always;
add_header Content-Disposition "inline" always;
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
}
location @uploads_bucket {
rewrite ^/uploads/(.*)$ /$1 break;
proxy_pass $upstream_garage_web;
proxy_set_header Host uploads.web.garage;
location @uploads_disk {
root /uploads;
try_files $uri =404;
add_header X-Content-Type-Options nosniff always;
add_header Content-Disposition "inline" always;
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
+4 -4
View File
@@ -83,8 +83,8 @@
set $upstream_usaco http://usaco:8080;
# And the Dozzle log viewer's.
set $upstream_dozzle http://dozzle:8080;
# Garage: its website endpoint (the /uploads/ bucket fallback, used by
# the @uploads_bucket location in nginx.conf.template and
# Garage: its website endpoint (where /uploads/ is served from; see the
# /uploads/ location in nginx.conf.template and
# nginx_dev_common.conf.template) and the garage-webui admin UI.
set $upstream_garage_web http://garage:3902;
set $upstream_garage_webui http://garage-webui:3909;
@@ -115,7 +115,7 @@
# breaking auth behind TLS termination.
#
# Ordering matters: nginx picks the longest matching prefix location,
# so the specific /ws, /auth/login and /messages/upload blocks (and
# so the specific /ws, /auth/login and /uploads blocks (and
# production's /graphql block in nginx.conf.template) win over the
# catch-all <PREFIX>/ block regardless of file order.
location $BACKEND_ENDPOINT {
@@ -154,7 +154,7 @@
proxy_set_header X-Forwarded-Proto $scheme;
}
location $BACKEND_ENDPOINT/messages/upload {
location $BACKEND_ENDPOINT/uploads {
limit_req zone=upload burst=20 nodelay;
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
proxy_pass $upstream_backend;