fix: FileBrowser upload uses auth query param, no CORS preflight for external users

This commit is contained in:
Krao Hasanee
2026-06-02 14:12:24 -04:00
parent 770bb1c05b
commit e11ef45140
+3 -3
View File
@@ -214,8 +214,8 @@ export default function FileBrowser({ initialPath = '/', rootPath = '/' }) {
async function uploadOneFile(url, token, fbPath, file, retries = 3) { async function uploadOneFile(url, token, fbPath, file, retries = 3) {
for (let attempt = 1; attempt <= retries; attempt++) { for (let attempt = 1; attempt <= retries; attempt++) {
try { try {
const res = await fetch(`${url}/api/resources?source=srv&path=${encodeURIComponent(fbPath)}&override=true`, { const res = await fetch(`${url}/api/resources?source=srv&path=${encodeURIComponent(fbPath)}&override=true&auth=${encodeURIComponent(token)}`, {
method: 'POST', headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/octet-stream' }, body: file, method: 'POST', headers: { 'Content-Type': 'application/octet-stream' }, body: file,
}); });
if (!res.ok) { const t = await res.text(); throw new Error(t || res.status); } if (!res.ok) { const t = await res.text(); throw new Error(t || res.status); }
return; return;
@@ -258,7 +258,7 @@ export default function FileBrowser({ initialPath = '/', rootPath = '/' }) {
for (let i = 1; i <= parts.length; i++) dirsNeeded.add(parts.slice(0, i).join('/')); for (let i = 1; i <= parts.length; i++) dirsNeeded.add(parts.slice(0, i).join('/'));
} }
for (const dir of [...dirsNeeded].sort((a, b) => a.split('/').length - b.split('/').length)) { for (const dir of [...dirsNeeded].sort((a, b) => a.split('/').length - b.split('/').length)) {
await fetch(`${url}/api/resources?source=srv&path=${encodeURIComponent(joinVirtualPath(fbPath, dir))}&isDir=true`, { method: 'POST', headers: { Authorization: `Bearer ${token}` } }).catch(() => {}); await fetch(`${url}/api/resources?source=srv&path=${encodeURIComponent(joinVirtualPath(fbPath, dir))}&isDir=true&auth=${encodeURIComponent(token)}`, { method: 'POST' }).catch(() => {});
} }
for (let i = 0; i < sel.length; i++) { for (let i = 0; i < sel.length; i++) {
await uploadOneFile(url, token, joinVirtualPath(fbPath, sel[i].webkitRelativePath), sel[i]); await uploadOneFile(url, token, joinVirtualPath(fbPath, sel[i].webkitRelativePath), sel[i]);