From 480a06c4262969b36742badd1e6c6a0a5be7ac3c Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Tue, 5 Jun 2018 15:26:24 -0700 Subject: [PATCH] track bytes sent on download --- server/routes/download.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/routes/download.js b/server/routes/download.js index bfd667ed..b320d899 100644 --- a/server/routes/download.js +++ b/server/routes/download.js @@ -14,8 +14,12 @@ module.exports = async function(req, res) { 'WWW-Authenticate': `send-v1 ${req.nonce}` }); const file_stream = storage.get(id); - + let sentBytes = 0; + file_stream.on('data', c => (sentBytes += c.length)); file_stream.on('end', async () => { + if (sentBytes < contentLength) { + return; + } const dl = meta.dl + 1; const dlimit = meta.dlimit; try {