From cb0d69c5cd7a88cd96c0efc707b58921c170c419 Mon Sep 17 00:00:00 2001 From: Abhinav Adduri Date: Thu, 20 Jul 2017 16:06:06 -0700 Subject: [PATCH] fixed one bug, added some helper functions --- frontend/src/download.js | 6 ++---- frontend/src/upload.js | 20 +++++++------------- frontend/src/utils.js | 13 ++++++++++++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/frontend/src/download.js b/frontend/src/download.js index 5203b70f..1f1ee5b1 100644 --- a/frontend/src/download.js +++ b/frontend/src/download.js @@ -1,5 +1,5 @@ const FileReceiver = require('./fileReceiver'); -const { notify, findMetric } = require('./utils'); +const { notify, findMetric, isFile } = require('./utils'); const $ = require('jquery'); require('jquery-circle-progress'); @@ -67,9 +67,7 @@ $(document).ready(function() { for (let i = 0; i < localStorage.length; i++) { const id = localStorage.key(i); - if (id !== 'totalUploads' && - id !== 'totalDownloads' && - id !== 'referrer') { + if (isFile(id)) { unexpiredFiles += 1; } } diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 4810d017..47136966 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -1,5 +1,5 @@ const FileSender = require('./fileSender'); -const { notify, gcmCompliant, findMetric } = require('./utils'); +const { notify, gcmCompliant, findMetric, isFile, ONE_DAY_IN_MS } = require('./utils'); const $ = require('jquery'); require('jquery-circle-progress'); @@ -235,13 +235,11 @@ $(document).ready(function() { let t; const startTime = new Date().getTime(); - let unexpiredFiles = 0; + let unexpiredFiles = 1; for (let i = 0; i < localStorage.length; i++) { const id = localStorage.key(i); - if (id !== 'totalUploads' && - id !== 'totalDownloads' && - id !== 'referrer') { + if (isFile(id)) { unexpiredFiles += 1; } } @@ -347,9 +345,7 @@ $(document).ready(function() { populateFileList(localStorage.getItem(id)); } } else if (xhr.status === 404) { - if (id !== 'totalUploads' && - id !== 'totalDownloads' && - id !== 'referrer') { + if (isFile(id)) { localStorage.removeItem(id); } } @@ -505,9 +501,7 @@ $(document).ready(function() { for (let i = 0; i < localStorage.length; i++) { const id = localStorage.key(i); - if (id !== 'totalUploads' && - id !== 'totalDownloads' && - id !== 'referrer') { + if (isFile(id)) { unexpiredFiles += 1; } } @@ -521,7 +515,7 @@ $(document).ready(function() { $popupText.find('.del-file').click(e => { FileSender.delete(file.fileId, file.deleteToken).then(() => { $(e.target).parents('tr').remove(); - const timeToExpiry = 86400000 - (new Date().getTime() - file.creationDate.getTime()); + const timeToExpiry = ONE_DAY_IN_MS - (new Date().getTime() - file.creationDate.getTime()); // record upload-deleted from file list window.analytics .sendEvent('sender', 'upload-deleted', { @@ -544,7 +538,7 @@ $(document).ready(function() { document.getElementById('delete-file').onclick = () => { FileSender.delete(file.fileId, file.deleteToken).then(() => { - const timeToExpiry = 86400000 - (new Date().getTime() - file.creationDate.getTime()); + const timeToExpiry = ONE_DAY_IN_MS - (new Date().getTime() - file.creationDate.getTime()); // record upload-deleted from success screen window.analytics .sendEvent('sender', 'upload-deleted', { diff --git a/frontend/src/utils.js b/frontend/src/utils.js index 473ac045..a814d769 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -94,10 +94,21 @@ function findMetric(href) { } } +function isFile(id) { + return !['referrer', + 'totalDownloads', + 'totalUploads', + 'testpilot_ga__cid'].includes(id); +} + +const ONE_DAY_IN_MS = 86400000; + module.exports = { arrayToHex, hexToArray, notify, gcmCompliant, - findMetric + findMetric, + isFile, + ONE_DAY_IN_MS };