npm run format

This commit is contained in:
Danny Coates 2017-07-21 17:01:26 -07:00
parent 5ed4db9689
commit 0d5fb1740d
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
11 changed files with 241 additions and 216 deletions

View file

@ -7,4 +7,4 @@ window.analytics = new testPilotGA({
an: 'Firefox Send',
ds: 'web',
tid: window.trackerId
})
});

View file

@ -18,12 +18,10 @@ $(document).ready(function() {
target.preventDefault();
sendEvent('recipient', 'restarted', {
cd2: 'completed'
})
.then(() => {
}).then(() => {
location.href = target.currentTarget.href;
});
})
});
$('.legal-links a, .social-links a, #dl-firefox').click(function(target) {
target.preventDefault();
@ -31,15 +29,14 @@ $(document).ready(function() {
// record exited event by recipient
sendEvent('recipient', 'exited', {
cd3: metric
})
.then(() => {
}).then(() => {
location.href = target.currentTarget.href;
});
})
});
$('#expired-send-new').click(function() {
storage.referrer = 'errored-download';
})
});
const filename = $('#dl-filename').html();
const bytelength = Number($('#dl-bytelength').text());
@ -60,9 +57,7 @@ $(document).ready(function() {
const fileReceiver = new FileReceiver();
const unexpiredFiles = storage.numFiles;
fileReceiver.on('progress', progress => {
window.onunload = function() {
storage.referrer = 'cancelled-download';
// record download-stopped (cancelled by tab close or reload)
@ -72,8 +67,8 @@ $(document).ready(function() {
cm6: unexpiredFiles,
cm7: storage.totalDownloads,
cd2: 'cancelled'
})
}
});
};
$('#download-page-one').attr('hidden', true);
$('#download-progress').removeAttr('hidden');
@ -81,15 +76,21 @@ $(document).ready(function() {
// update progress bar
$('#dl-progress').circleProgress('value', percent);
$('.percent-number').html(`${Math.floor(percent * 100)}`);
$('.progress-text').text(`${filename} (${bytes(progress[0], {decimalPlaces: 1, fixedDecimals: true})} of ${bytes(progress[1], {decimalPlaces: 1})})`);
$('.progress-text').text(
`${filename} (${bytes(progress[0], {
decimalPlaces: 1,
fixedDecimals: true
})} of ${bytes(progress[1], { decimalPlaces: 1 })})`
);
//on complete
if (percent === 1) {
fileReceiver.removeAllListeners('progress');
document.l10n.formatValues('downloadNotification', 'downloadFinish')
.then(translated => {
notify(translated[0]);
$('.title').html(translated[1]);
});
document.l10n
.formatValues('downloadNotification', 'downloadFinish')
.then(translated => {
notify(translated[0]);
$('.title').html(translated[1]);
});
window.onunload = null;
}
});
@ -138,10 +139,9 @@ $(document).ready(function() {
cd6: err
});
document.l10n.formatValue('expiredPageHeader')
.then(translated => {
$('.title').text(translated);
});
document.l10n.formatValue('expiredPageHeader').then(translated => {
$('.title').text(translated);
});
$('#download-btn').attr('hidden', true);
$('#expired-img').removeAttr('hidden');
console.log('The file has expired, or has already been deleted.');

View file

@ -58,41 +58,46 @@ class FileReceiver extends EventEmitter {
true,
['encrypt', 'decrypt']
)
]).then(([fdata, key]) => {
this.emit('decrypting', true);
return Promise.all([
window.crypto.subtle.decrypt(
{
name: 'AES-GCM',
iv: hexToArray(fdata.iv),
additionalData: hexToArray(fdata.aad)
},
key,
fdata.data
).then(decrypted => {
this.emit('decrypting', false);
return Promise.resolve(decrypted)
}),
fdata.filename,
hexToArray(fdata.aad)
]);
}).then(([decrypted, fname, proposedHash]) => {
this.emit('hashing', true);
return window.crypto.subtle.digest('SHA-256', decrypted).then(calculatedHash => {
this.emit('hashing', false);
const integrity = new Uint8Array(calculatedHash).toString() === proposedHash.toString();
if (!integrity) {
this.emit('unsafe', true)
return Promise.reject();
} else {
this.emit('safe', true);
return Promise.all([
decrypted,
decodeURIComponent(fname)
]);
}
])
.then(([fdata, key]) => {
this.emit('decrypting', true);
return Promise.all([
window.crypto.subtle
.decrypt(
{
name: 'AES-GCM',
iv: hexToArray(fdata.iv),
additionalData: hexToArray(fdata.aad)
},
key,
fdata.data
)
.then(decrypted => {
this.emit('decrypting', false);
return Promise.resolve(decrypted);
}),
fdata.filename,
hexToArray(fdata.aad)
]);
})
})
.then(([decrypted, fname, proposedHash]) => {
this.emit('hashing', true);
return window.crypto.subtle
.digest('SHA-256', decrypted)
.then(calculatedHash => {
this.emit('hashing', false);
const integrity =
new Uint8Array(calculatedHash).toString() ===
proposedHash.toString();
if (!integrity) {
this.emit('unsafe', true);
return Promise.reject();
} else {
this.emit('safe', true);
return Promise.all([decrypted, decodeURIComponent(fname)]);
}
});
});
}
}

View file

@ -2,9 +2,9 @@ const { isFile } = require('./utils');
class Storage {
constructor(engine) {
this.engine = engine
this.engine = engine;
}
get totalDownloads() {
return Number(this.engine.getItem('totalDownloads'));
}
@ -23,7 +23,7 @@ class Storage {
set referrer(str) {
this.engine.setItem('referrer', str);
}
get files() {
const fs = [];
for (let i = 0; i < this.engine.length; i++) {
@ -49,7 +49,7 @@ class Storage {
getFileById(id) {
return this.engine.getItem(id);
}
has(property) {
return this.engine.hasOwnProperty(property);
}
@ -57,10 +57,10 @@ class Storage {
remove(property) {
this.engine.removeItem(property);
}
addFile(id, file) {
this.engine.setItem(id, JSON.stringify(file));
}
}
module.exports = Storage;
module.exports = Storage;

View file

@ -1,7 +1,13 @@
/* global MAXFILESIZE */
require('./common');
const FileSender = require('./fileSender');
const { notify, gcmCompliant, findMetric, sendEvent, ONE_DAY_IN_MS } = require('./utils');
const {
notify,
gcmCompliant,
findMetric,
sendEvent,
ONE_DAY_IN_MS
} = require('./utils');
const bytes = require('bytes');
const Storage = require('./storage');
const storage = new Storage(localStorage);
@ -19,15 +25,13 @@ if (storage.has('referrer')) {
}
$(document).ready(function() {
gcmCompliant()
.catch(err => {
$('#page-one').attr('hidden', true);
$('#unsupported-browser').removeAttr('hidden');
// record unsupported event
sendEvent('sender', 'unsupported', {
cd6: err
});
gcmCompliant().catch(err => {
$('#page-one').attr('hidden', true);
$('#unsupported-browser').removeAttr('hidden');
// record unsupported event
sendEvent('sender', 'unsupported', {
cd6: err
});
});
$('#file-upload').change(onUpload);
@ -38,35 +42,32 @@ $(document).ready(function() {
// record exited event by recipient
sendEvent('sender', 'exited', {
cd3: metric
})
.then(() => {
}).then(() => {
location.href = target.currentTarget.href;
});
})
});
$('#send-new-completed').click(function(target) {
target.preventDefault();
// record restarted event
sendEvent('sender', 'restarted', {
cd2: 'completed'
})
.then(() => {
}).then(() => {
storage.referrer = 'completed-upload';
location.href = target.currentTarget.href;
});
})
});
$('#send-new-error').click(function(target) {
target.preventDefault();
// record restarted event
sendEvent('sender', 'restarted', {
cd2: 'errored'
})
.then(() => {
}).then(() => {
storage.referrer = 'errored-upload';
location.href = target.currentTarget.href;
});
})
});
$('body').on('dragover', allowDrop).on('drop', onUpload);
// reset copy button
@ -87,7 +88,6 @@ $(document).ready(function() {
}
}
// copy link to clipboard
$copyBtn.click(() => {
// record copied event from success screen
@ -103,7 +103,9 @@ $(document).ready(function() {
//disable button for 3s
$copyBtn.attr('disabled', true);
$('#link').attr('disabled', true);
$copyBtn.html('<img src="/resources/check-16.svg" class="icon-check"></img>');
$copyBtn.html(
'<img src="/resources/check-16.svg" class="icon-check"></img>'
);
window.setTimeout(() => {
$copyBtn.attr('disabled', false);
$('#link').attr('disabled', false);
@ -137,12 +139,14 @@ $(document).ready(function() {
let file = '';
if (event.type === 'drop') {
if (event.originalEvent.dataTransfer.files.length > 1 || event.originalEvent.dataTransfer.files[0].size === 0){
if (
event.originalEvent.dataTransfer.files.length > 1 ||
event.originalEvent.dataTransfer.files[0].size === 0
) {
$('.upload-window').removeClass('ondrag');
document.l10n.formatValue('uploadPageMultipleFilesAlert')
.then(str => {
alert(str);
});
document.l10n.formatValue('uploadPageMultipleFilesAlert').then(str => {
alert(str);
});
return;
}
file = event.originalEvent.dataTransfer.files[0];
@ -151,7 +155,9 @@ $(document).ready(function() {
}
if (file.size > MAXFILESIZE) {
return document.l10n.formatValue('fileTooBig', {size: bytes(MAXFILESIZE)}).then(alert);
return document.l10n
.formatValue('fileTooBig', { size: bytes(MAXFILESIZE) })
.then(alert);
}
$('#page-one').attr('hidden', true);
@ -165,10 +171,9 @@ $(document).ready(function() {
$('#cancel-upload').click(() => {
fileSender.cancel();
location.reload();
document.l10n.formatValue('uploadCancelNotification')
.then(str => {
notify(str);
});
document.l10n.formatValue('uploadCancelNotification').then(str => {
notify(str);
});
storage.referrer = 'cancelled-upload';
// record upload-stopped (cancelled) by sender
@ -189,7 +194,12 @@ $(document).ready(function() {
$('#ul-progress').circleProgress().on('circle-animation-end', function() {
$('.percent-number').html(`${Math.floor(percent * 100)}`);
});
$('.progress-text').text(`${file.name} (${bytes(progress[0], {decimalPlaces: 1, fixedDecimals: true})} of ${bytes(progress[1], {decimalPlaces: 1})})`);
$('.progress-text').text(
`${file.name} (${bytes(progress[0], {
decimalPlaces: 1,
fixedDecimals: true
})} of ${bytes(progress[1], { decimalPlaces: 1 })})`
);
});
fileSender.on('loading', isStillLoading => {
@ -245,15 +255,15 @@ $(document).ready(function() {
// record upload-stopped (completed) by sender
sendEvent('sender', 'upload-stopped', {
cm1: file.size,
cm2: totalTime,
cm3: uploadSpeed,
cm5: storage.totalUploads,
cm6: unexpiredFiles,
cm7: storage.totalDownloads,
cd1: event.type === 'drop' ? 'drop' : 'click',
cd2: 'completed'
});
cm1: file.size,
cm2: totalTime,
cm3: uploadSpeed,
cm5: storage.totalUploads,
cm6: unexpiredFiles,
cm7: storage.totalDownloads,
cd1: event.type === 'drop' ? 'drop' : 'click',
cd2: 'completed'
});
const fileData = {
name: file.name,
@ -270,7 +280,10 @@ $(document).ready(function() {
};
storage.addFile(info.fileId, fileData);
$('#upload-filename').attr('data-l10n-id', 'uploadSuccessConfirmHeader');
$('#upload-filename').attr(
'data-l10n-id',
'uploadSuccessConfirmHeader'
);
t = window.setTimeout(() => {
$('#page-one').attr('hidden', true);
$('#upload-progress').attr('hidden', true);
@ -279,10 +292,9 @@ $(document).ready(function() {
}, 1000);
populateFileList(fileData);
document.l10n.formatValue('notifyUploadDone')
.then(str => {
notify(str);
});
document.l10n.formatValue('notifyUploadDone').then(str => {
notify(str);
});
})
.catch(err => {
Raven.captureException(err);
@ -334,10 +346,18 @@ $(document).ready(function() {
const row = document.createElement('tr');
const name = document.createElement('td');
const link = document.createElement('td');
const $copyIcon = $('<img>', { src: '/resources/copy-16.svg', class: 'icon-copy', 'data-l10n-id': 'copyUrlHover'});
const $copyIcon = $('<img>', {
src: '/resources/copy-16.svg',
class: 'icon-copy',
'data-l10n-id': 'copyUrlHover'
});
const expiry = document.createElement('td');
const del = document.createElement('td');
const $delIcon = $('<img>', { src: '/resources/close-16.svg', class: 'icon-delete', 'data-l10n-id': 'deleteButtonHover' });
const $delIcon = $('<img>', {
src: '/resources/close-16.svg',
class: 'icon-delete',
'data-l10n-id': 'deleteButtonHover'
});
const popupDiv = document.createElement('div');
const $popupText = $('<div>', { class: 'popuptext' });
const cellText = document.createTextNode(file.name);
@ -345,14 +365,8 @@ $(document).ready(function() {
const url = file.url.trim() + `#${file.secretKey}`.trim();
$('#link').attr('value', url);
$('#copy-text').attr(
'data-l10n-args',
'{"filename": "' + file.name + '"}'
);
$('#copy-text').attr(
'data-l10n-id',
'copyUrlFormLabelWithName'
);
$('#copy-text').attr('data-l10n-args', '{"filename": "' + file.name + '"}');
$('#copy-text').attr('data-l10n-id', 'copyUrlFormLabelWithName');
$popupText.attr('tabindex', '-1');
name.appendChild(cellText);
@ -383,10 +397,9 @@ $(document).ready(function() {
aux.select();
document.execCommand('copy');
document.body.removeChild(aux);
document.l10n.formatValue('copiedUrl')
.then(translated => {
link.innerHTML = translated;
});
document.l10n.formatValue('copiedUrl').then(translated => {
link.innerHTML = translated;
});
window.setTimeout(() => {
const linkImg = document.createElement('img');
$(linkImg).addClass('icon-copy');
@ -446,12 +459,7 @@ $(document).ready(function() {
$(popupNvmSpan).addClass('nvm');
$(popupNvmSpan).attr('data-l10n-id', 'nevermindButton');
$popupText.html([
popupDelSpan,
'&nbsp;',
'&nbsp;',
popupNvmSpan
]);
$popupText.html([popupDelSpan, '&nbsp;', '&nbsp;', popupNvmSpan]);
// add data cells to table row
row.appendChild(name);
@ -470,7 +478,8 @@ $(document).ready(function() {
$popupText.find('.del-file').click(e => {
FileSender.delete(file.fileId, file.deleteToken).then(() => {
$(e.target).parents('tr').remove();
const timeToExpiry = ONE_DAY_IN_MS - (Date.now() - file.creationDate.getTime());
const timeToExpiry =
ONE_DAY_IN_MS - (Date.now() - file.creationDate.getTime());
// record upload-deleted from file list
sendEvent('sender', 'upload-deleted', {
cm1: file.size,
@ -482,17 +491,17 @@ $(document).ready(function() {
cm7: storage.totalDownloads,
cd1: file.typeOfUpload,
cd4: 'upload-list'
})
.then(() => {
}).then(() => {
storage.remove(file.fileId);
})
});
toggleHeader();
});
});
document.getElementById('delete-file').onclick = () => {
FileSender.delete(file.fileId, file.deleteToken).then(() => {
const timeToExpiry = ONE_DAY_IN_MS - (Date.now() - file.creationDate.getTime());
const timeToExpiry =
ONE_DAY_IN_MS - (Date.now() - file.creationDate.getTime());
// record upload-deleted from success screen
sendEvent('sender', 'upload-deleted', {
cm1: file.size,
@ -504,11 +513,10 @@ $(document).ready(function() {
cm7: storage.totalDownloads,
cd1: file.typeOfUpload,
cd4: 'success-screen'
})
.then(() => {
}).then(() => {
storage.remove(file.fileId);
location.reload();
})
});
});
};
// show popup
@ -529,7 +537,6 @@ $(document).ready(function() {
$popupText.removeClass('show');
});
toggleHeader();
}
function toggleHeader() {

View file

@ -70,7 +70,7 @@ function gcmCompliant() {
}
function findMetric(href) {
switch(href) {
switch (href) {
case 'https://www.mozilla.org/':
return 'mozilla';
case 'https://www.mozilla.org/about/legal':
@ -95,17 +95,18 @@ function findMetric(href) {
}
function isFile(id) {
return !['referrer',
'totalDownloads',
'totalUploads',
'testpilot_ga__cid'].includes(id);
return ![
'referrer',
'totalDownloads',
'totalUploads',
'testpilot_ga__cid'
].includes(id);
}
function sendEvent() {
return window.analytics
.sendEvent
.apply(window.analytics, arguments)
.catch(() => 0);
return window.analytics.sendEvent
.apply(window.analytics, arguments)
.catch(() => 0);
}
const ONE_DAY_IN_MS = 86400000;