fixed one bug, added some helper functions

This commit is contained in:
Abhinav Adduri 2017-07-20 16:06:06 -07:00
parent b9eb653f1f
commit cb0d69c5cd
3 changed files with 21 additions and 18 deletions

View File

@ -1,5 +1,5 @@
const FileReceiver = require('./fileReceiver'); const FileReceiver = require('./fileReceiver');
const { notify, findMetric } = require('./utils'); const { notify, findMetric, isFile } = require('./utils');
const $ = require('jquery'); const $ = require('jquery');
require('jquery-circle-progress'); require('jquery-circle-progress');
@ -67,9 +67,7 @@ $(document).ready(function() {
for (let i = 0; i < localStorage.length; i++) { for (let i = 0; i < localStorage.length; i++) {
const id = localStorage.key(i); const id = localStorage.key(i);
if (id !== 'totalUploads' && if (isFile(id)) {
id !== 'totalDownloads' &&
id !== 'referrer') {
unexpiredFiles += 1; unexpiredFiles += 1;
} }
} }

View File

@ -1,5 +1,5 @@
const FileSender = require('./fileSender'); const FileSender = require('./fileSender');
const { notify, gcmCompliant, findMetric } = require('./utils'); const { notify, gcmCompliant, findMetric, isFile, ONE_DAY_IN_MS } = require('./utils');
const $ = require('jquery'); const $ = require('jquery');
require('jquery-circle-progress'); require('jquery-circle-progress');
@ -235,13 +235,11 @@ $(document).ready(function() {
let t; let t;
const startTime = new Date().getTime(); const startTime = new Date().getTime();
let unexpiredFiles = 0; let unexpiredFiles = 1;
for (let i = 0; i < localStorage.length; i++) { for (let i = 0; i < localStorage.length; i++) {
const id = localStorage.key(i); const id = localStorage.key(i);
if (id !== 'totalUploads' && if (isFile(id)) {
id !== 'totalDownloads' &&
id !== 'referrer') {
unexpiredFiles += 1; unexpiredFiles += 1;
} }
} }
@ -347,9 +345,7 @@ $(document).ready(function() {
populateFileList(localStorage.getItem(id)); populateFileList(localStorage.getItem(id));
} }
} else if (xhr.status === 404) { } else if (xhr.status === 404) {
if (id !== 'totalUploads' && if (isFile(id)) {
id !== 'totalDownloads' &&
id !== 'referrer') {
localStorage.removeItem(id); localStorage.removeItem(id);
} }
} }
@ -505,9 +501,7 @@ $(document).ready(function() {
for (let i = 0; i < localStorage.length; i++) { for (let i = 0; i < localStorage.length; i++) {
const id = localStorage.key(i); const id = localStorage.key(i);
if (id !== 'totalUploads' && if (isFile(id)) {
id !== 'totalDownloads' &&
id !== 'referrer') {
unexpiredFiles += 1; unexpiredFiles += 1;
} }
} }
@ -521,7 +515,7 @@ $(document).ready(function() {
$popupText.find('.del-file').click(e => { $popupText.find('.del-file').click(e => {
FileSender.delete(file.fileId, file.deleteToken).then(() => { FileSender.delete(file.fileId, file.deleteToken).then(() => {
$(e.target).parents('tr').remove(); $(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 // record upload-deleted from file list
window.analytics window.analytics
.sendEvent('sender', 'upload-deleted', { .sendEvent('sender', 'upload-deleted', {
@ -544,7 +538,7 @@ $(document).ready(function() {
document.getElementById('delete-file').onclick = () => { document.getElementById('delete-file').onclick = () => {
FileSender.delete(file.fileId, file.deleteToken).then(() => { 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 // record upload-deleted from success screen
window.analytics window.analytics
.sendEvent('sender', 'upload-deleted', { .sendEvent('sender', 'upload-deleted', {

View File

@ -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 = { module.exports = {
arrayToHex, arrayToHex,
hexToArray, hexToArray,
notify, notify,
gcmCompliant, gcmCompliant,
findMetric findMetric,
isFile,
ONE_DAY_IN_MS
}; };