From 238ff0b603dd901300095f952cf4b272ab475037 Mon Sep 17 00:00:00 2001 From: Hayden Hargreaves Date: Wed, 5 Mar 2025 14:27:21 -0700 Subject: [PATCH] FIX: Download only works when valid files are selected. --- backend/src/server.ts | 2 +- frontend/src/pages/Dashboard.jsx | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/src/server.ts b/backend/src/server.ts index 400a23e..57cebac 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -131,7 +131,7 @@ v1.post("/download", (req: Request, res: Response): void => { // Validate the path array if (!filePaths || !Array.isArray(filePaths) || filePaths.length === 0) { - res.status(400).send({error: 'Invalid file paths provided.'}); + res.status(400).send({code: 400, error: 'Invalid file paths provided.'}); return; } diff --git a/frontend/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx index 1e26443..8126baa 100644 --- a/frontend/src/pages/Dashboard.jsx +++ b/frontend/src/pages/Dashboard.jsx @@ -137,19 +137,20 @@ export default function Dashboard() { body: JSON.stringify({filePaths: paths}), }); if (!resp.ok) { - setError(`HTTP error! status: ${resp.status}`); + const data = await resp.json(); + setError(`Error ${data.code}: ${data.error}`); + } else { + // TODO: Figure out how tf this works. + const blob = await resp.blob(); + const url = window.URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = "downloads.zip"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + window.URL.revokeObjectURL(url); } - - // TODO: Figure out how tf this works. - const blob = await resp.blob(); - const url = window.URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = "downloads.zip"; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - window.URL.revokeObjectURL(url); } catch (err) { console.error(`Download error: ${err}`); }