From 59ba89262f3c9d1a893b4c5ec06c92eb2e6b6d25 Mon Sep 17 00:00:00 2001 From: Emily Hou <39499244+emily-hou1@users.noreply.github.com> Date: Tue, 17 Jul 2018 09:48:47 -0700 Subject: [PATCH] fix download count on server (#863) --- app/api.js | 1 - server/routes/download.js | 3 ++- test/frontend/tests/workflow-tests.js | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/api.js b/app/api.js index 7d9fb394..99ba8bad 100644 --- a/app/api.js +++ b/app/api.js @@ -169,7 +169,6 @@ function download(id, keychain, onprogress, canceller) { const auth = await keychain.authHeader(); xhr.open('get', `/api/download/${id}`); xhr.setRequestHeader('Authorization', auth); - xhr.setRequestHeader('Connection', 'close'); xhr.responseType = 'blob'; xhr.send(); onprogress([0, 1]); diff --git a/server/routes/download.js b/server/routes/download.js index 84ba715d..8e1ecf98 100644 --- a/server/routes/download.js +++ b/server/routes/download.js @@ -21,10 +21,11 @@ module.exports = async function(req, res) { file_stream.destroy(); }); - file_stream.on('close', async () => { + file_stream.on('end', async () => { if (cancelled) { return; } + const dl = meta.dl + 1; const dlimit = meta.dlimit; try { diff --git a/test/frontend/tests/workflow-tests.js b/test/frontend/tests/workflow-tests.js index 69eba9dd..a378d28c 100644 --- a/test/frontend/tests/workflow-tests.js +++ b/test/frontend/tests/workflow-tests.js @@ -134,7 +134,23 @@ describe('Upload / Download flow', function() { } }); - it('can cancel and not increase download count', async function() { + it('can increase download count on download', async function() { + const fs = new FileSender(blob); + const file = await fs.upload(); + const fr = new FileReceiver({ + secretKey: file.toJSON().secretKey, + id: file.id, + nonce: file.keychain.nonce, + requiresPassword: false + }); + await fr.getMetadata(); + + await fr.download(noSave); + await file.updateDownloadCount(); + assert.equal(file.dtotal, 1); + }); + + it('does not increase download count when download cancelled', async function() { const fs = new FileSender(blob); const file = await fs.upload(); const fr = new FileReceiver({