fix(media): clean up files after response finishes

main
Peter Steinberger 2025-12-02 21:10:18 +00:00
parent a0d1004909
commit 4e20a20927
1 changed files with 5 additions and 3 deletions

View File

@ -42,9 +42,11 @@ export function attachMediaRoutes(
if (mime) res.type(mime);
res.send(data);
// best-effort single-use cleanup after response ends
setTimeout(() => {
fs.rm(realPath).catch(() => {});
}, 500);
res.on("finish", () => {
setTimeout(() => {
fs.rm(realPath).catch(() => {});
}, 50);
});
} catch {
res.status(404).send("not found");
}