FIX: Download only works when valid files are selected.
This commit is contained in:
parent
c9eeddc2b6
commit
238ff0b603
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user