feat: allow cleanup via REMOVE_DOWNLOAD env

This commit is contained in:
2019-11-27 14:30:11 -07:00
parent 65c8e1be3c
commit 3792de3c91

View File

@@ -89,6 +89,19 @@ module.exports = async function server(req, res) {
sent = true; sent = true;
}); });
} }
sent = true; sent = true;
// clean up the download if told to
res.on('finish', () => {
const { REMOVE_DOWNLOAD } = process.env;
if (!REMOVE_DOWNLOAD) return;
const shouldRemove = REMOVE_DOWNLOAD === '1' || REMOVE_DOWNLOAD.toLowerCase() === 'true';
if (shouldRemove) {
logger.info('Removing local file:', dlFilepath);
fs.unlinkSync(dlFilepath);
}
});
}); });
}; };