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
+8 -12
View File
@@ -8,7 +8,7 @@
import { defineStore } from "pinia";
import { ref, computed } from "vue";
import axios from "axios";
import { uploadFile } from "@/uploads";
/**
* Same-origin ws:// or wss:// URL for the chat socket, derived from the page's
@@ -133,21 +133,17 @@ export const useMessagesStore = defineStore("messages", () => {
}
/**
* POST a file to the REST upload endpoint, then send its returned URL over
* the socket as a normal message. Two steps because the socket carries JSON
* text only. Errors surface via `lastError`.
* Store a file (uploads.js), then send its URL over the socket as a normal
* message. Two steps because the socket carries JSON text only. Errors
* surface via `lastError`.
*
* `private` is sent with the upload as well as with the message: the backend
* stores private attachments under /uploads/private/, which nginx gates
* behind an admin check.
* `private` goes to both: the upload is stored under /uploads/private/,
* which nginx gates behind an admin check, and the message is marked
* private. The two must agree.
*/
async function uploadAndSendFile(file, isPrivate = false) {
try {
const formData = new FormData();
formData.append("file", file);
formData.append("private", isPrivate ? "true" : "false");
const res = await axios.post("/api/messages/upload", formData);
const { url } = res.data;
const url = await uploadFile(file, { private: isPrivate });
if (!socket.value || !isConnected.value) return;
socket.value.send(
JSON.stringify({ text: "", fileUrl: url, private: isPrivate }),