From 9e0048eec27241f041bd9b8ff9d2a84f1a066903 Mon Sep 17 00:00:00 2001 From: Fabian Mendoza Date: Thu, 23 Jul 2026 11:24:57 -0400 Subject: [PATCH] fix(content): respect current folder when uploading files (#211) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the dashboard upload always sent files to root (folder_id=NULL) because the upload flow never read or forwarded the current folder context. The agency upload already handled this correctly — this applies the same pattern. Changes: - api.js: uploadContent() accepts optional folderId, appends to FormData - content-library.js: handleFiles() passes state.currentFolderId - content.js: POST / reads folder_id from multipart body --- frontend/js/api.js | 3 ++- frontend/js/views/content-library.js | 2 +- server/routes/content.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/js/api.js b/frontend/js/api.js index a8c4d93..0489e19 100644 --- a/frontend/js/api.js +++ b/frontend/js/api.js @@ -83,9 +83,10 @@ export const api = { body: JSON.stringify({ parent_id: parentId || null }) }), deleteFolder: (id) => request(`/folders/${id}`, { method: 'DELETE' }), - uploadContent: async (file, onProgress) => { + uploadContent: async (file, onProgress, folderId) => { const formData = new FormData(); formData.append('file', file); + if (folderId) formData.append('folder_id', folderId); return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); diff --git a/frontend/js/views/content-library.js b/frontend/js/views/content-library.js index 6452484..104283a 100644 --- a/frontend/js/views/content-library.js +++ b/frontend/js/views/content-library.js @@ -231,7 +231,7 @@ async function handleFiles(files) { await api.uploadContent(file, (pct) => { progressFill.style.width = pct + '%'; progressText.textContent = t('content.upload_progress_named_pct', { name: file.name, pct }); - }); + }, state.currentFolderId); showToast(t('content.toast.uploaded_named', { name: file.name }), 'success'); } catch (err) { showToast(t('content.toast.upload_failed_named', { name: file.name, error: err.message }), 'error'); diff --git a/server/routes/content.js b/server/routes/content.js index 5676a41..2d37523 100644 --- a/server/routes/content.js +++ b/server/routes/content.js @@ -99,7 +99,7 @@ router.post('/', checkStorageLimit, upload.single('file'), async (req, res) => { if (!req.file) return res.status(400).json({ error: 'No file uploaded' }); // #73: shared ingest - identical processing + insert for dashboard and agency uploads. - const content = await ingestUploadedFile({ file: req.file, userId: req.user.id, workspaceId: req.workspaceId }); + const content = await ingestUploadedFile({ file: req.file, userId: req.user.id, workspaceId: req.workspaceId, folderId: req.body.folder_id || null }); res.status(201).json(content); } catch (err) { console.error('Upload error:', err);