track bytes sent on download

This commit is contained in:
Danny Coates 2018-06-05 15:26:24 -07:00
parent f0530975ac
commit 480a06c426
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
1 changed files with 5 additions and 1 deletions

View File

@ -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 {