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,19 +137,20 @@ 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.
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) { } catch (err) {
console.error(`Download error: ${err}`); console.error(`Download error: ${err}`);
} }