fix: proxy file uploads server-side via action=upload, fixes CORS for all roles

This commit is contained in:
Krao Hasanee
2026-06-02 14:19:59 -04:00
parent e11ef45140
commit ae093a9b1c
3 changed files with 54 additions and 37 deletions
+2 -17
View File
@@ -207,26 +207,11 @@ async function fbqProxy(op, path, extra = {}) {
}
if (op === 'upload') {
const normalized = String(path || '/');
const parts = normalized.split('/').filter(Boolean);
const fileName = parts.pop() || '';
const parentPath = `/${parts.join('/')}` || '/';
const tokenResponse = await fetch(`/api/filebrowser?action=upload-token&sb_access_token=${encodeURIComponent(accessToken)}`, {
method: 'POST',
headers: { ...authHeaders, 'Content-Type': 'application/json' },
body: JSON.stringify({ path: parentPath }),
});
if (!tokenResponse.ok) {
const text = await tokenResponse.text();
throw new Error(text || `Error ${tokenResponse.status}`);
}
const { token, url, fbPath } = await tokenResponse.json();
if (!token || !url || !fbPath) throw new Error('Upload token unavailable.');
const file = extra.body?.get?.('file');
if (!file) throw new Error('No file provided.');
const uploadResponse = await fetch(`${url}/api/resources?source=srv&path=${encodeURIComponent(`${fbPath}/${fileName}`)}&override=true&auth=${encodeURIComponent(token)}`, {
const uploadResponse = await fetch(`/api/filebrowser?action=upload&path=${encodeURIComponent(path)}&sb_access_token=${encodeURIComponent(accessToken)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/octet-stream' },
headers: { ...authHeaders, 'Content-Type': 'application/octet-stream' },
body: file,
});
if (!uploadResponse.ok) {