FIX: Download only works when valid files are selected.

This commit is contained in:
Hayden Hargreaves 2025-03-05 14:27:21 -07:00
parent c9eeddc2b6
commit 238ff0b603
2 changed files with 14 additions and 13 deletions

View File

@ -131,7 +131,7 @@ v1.post("/download", (req: Request, res: Response): void => {
// Validate the path array // Validate the path array
if (!filePaths || !Array.isArray(filePaths) || filePaths.length === 0) { 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; return;
} }

View File

@ -137,9 +137,9 @@ export default function Dashboard() {
body: JSON.stringify({filePaths: paths}), body: JSON.stringify({filePaths: paths}),
}); });
if (!resp.ok) { 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. // TODO: Figure out how tf this works.
const blob = await resp.blob(); const blob = await resp.blob();
const url = window.URL.createObjectURL(blob); const url = window.URL.createObjectURL(blob);
@ -150,6 +150,7 @@ export default function Dashboard() {
a.click(); a.click();
document.body.removeChild(a); document.body.removeChild(a);
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
}
} catch (err) { } catch (err) {
console.error(`Download error: ${err}`); console.error(`Download error: ${err}`);
} }