fix cancelled downloads increasing count
This commit is contained in:
parent
dfea1e96fb
commit
5ff92c6452
@ -15,9 +15,14 @@ module.exports = async function(req, res) {
|
||||
});
|
||||
const file_stream = storage.get(id);
|
||||
let sentBytes = 0;
|
||||
let cancelled = false;
|
||||
|
||||
req.on('close', () => (cancelled = true));
|
||||
|
||||
file_stream.on('data', c => (sentBytes += c.length));
|
||||
|
||||
file_stream.on('end', async () => {
|
||||
if (sentBytes < contentLength) {
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
const dl = meta.dl + 1;
|
||||
@ -32,6 +37,7 @@ module.exports = async function(req, res) {
|
||||
log.info('StorageError:', id);
|
||||
}
|
||||
});
|
||||
|
||||
file_stream.pipe(res);
|
||||
} catch (e) {
|
||||
res.sendStatus(404);
|
||||
|
Loading…
Reference in New Issue
Block a user