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

@ -1,6 +1,6 @@
extends: stylelint-config-standard extends: stylelint-config-standard
rules: rules:
color-hex-case: upper color-hex-case: lower
declaration-colon-newline-after: null declaration-colon-newline-after: null
selector-list-comma-newline-after: null selector-list-comma-newline-after: null

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ const { isFile } = require('./utils');
class Storage { class Storage {
constructor(engine) { constructor(engine) {
this.engine = engine this.engine = engine;
} }
get totalDownloads() { get totalDownloads() {

View File

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

View File

@ -95,15 +95,16 @@ function findMetric(href) {
} }
function isFile(id) { function isFile(id) {
return !['referrer', return ![
'referrer',
'totalDownloads', 'totalDownloads',
'totalUploads', 'totalUploads',
'testpilot_ga__cid'].includes(id); 'testpilot_ga__cid'
].includes(id);
} }
function sendEvent() { function sendEvent() {
return window.analytics return window.analytics.sendEvent
.sendEvent
.apply(window.analytics, arguments) .apply(window.analytics, arguments)
.catch(() => 0); .catch(() => 0);
} }

View File

@ -27,7 +27,10 @@ body {
padding-bottom: 51px; padding-bottom: 51px;
} }
input, select, textarea, button { input,
select,
textarea,
button {
font-family: inherit; font-family: inherit;
} }
@ -49,7 +52,7 @@ a {
width: 630px; width: 630px;
text-align: center; text-align: center;
margin: 0 auto 60px; margin: 0 auto 60px;
color: #0C0C0D; color: #0c0c0d;
} }
.upload-window { .upload-window {
@ -80,7 +83,7 @@ a {
} }
.link { .link {
color: #0094FB; color: #0094fb;
text-decoration: none; text-decoration: none;
} }
@ -92,10 +95,10 @@ a {
} }
#browse { #browse {
background: #0297F8; background: #0297f8;
border-radius: 5px; border-radius: 5px;
font-size: 15px; font-size: 15px;
color: #FFF; color: #fff;
width: 240px; width: 240px;
height: 44px; height: 44px;
display: flex; display: flex;
@ -129,7 +132,7 @@ th {
td { td {
font-size: 15px; font-size: 15px;
vertical-align: top; vertical-align: top;
color: #4A4A4A; color: #4a4a4a;
padding: 17px 19px 0; padding: 17px 19px 0;
line-height: 23px; line-height: 23px;
} }
@ -149,7 +152,9 @@ tbody {
table-layout: fixed; table-layout: fixed;
} }
.icon-delete, .icon-copy, .icon-check { .icon-delete,
.icon-copy,
.icon-check {
cursor: pointer; cursor: pointer;
} }
@ -165,7 +170,7 @@ tbody {
visibility: hidden; visibility: hidden;
width: 160px; width: 160px;
background-color: #555; background-color: #555;
color: #FFF; color: #fff;
text-align: center; text-align: center;
border-radius: 6px; border-radius: 6px;
padding: 8px 0; padding: 8px 0;
@ -239,7 +244,7 @@ tbody {
} }
#cancel-upload { #cancel-upload {
color: #D70022; color: #d70022;
cursor: pointer; cursor: pointer;
text-decoration: underline; text-decoration: underline;
} }
@ -268,13 +273,13 @@ tbody {
align-self: flex-start; align-self: flex-start;
margin-top: 60px; margin-top: 60px;
margin-bottom: 10px; margin-bottom: 10px;
color: #0C0C0D; color: #0c0c0d;
} }
#link { #link {
width: 480px; width: 480px;
height: 56px; height: 56px;
border: 1px solid #0297F8; border: 1px solid #0297f8;
border-radius: 6px 0 0 6px; border-radius: 6px 0 0 6px;
font-size: 24px; font-size: 24px;
color: #737373; color: #737373;
@ -284,15 +289,15 @@ tbody {
} }
#link:disabled { #link:disabled {
border: 1px solid #05A700; border: 1px solid #05a700;
background: #FFF; background: #fff;
} }
#copy-btn { #copy-btn {
width: 165px; width: 165px;
height: 60px; height: 60px;
background: #0297F8; background: #0297f8;
border: 1px solid #0297F8; border: 1px solid #0297f8;
border-radius: 0 6px 6px 0; border-radius: 0 6px 6px 0;
color: white; color: white;
cursor: pointer; cursor: pointer;
@ -300,15 +305,15 @@ tbody {
} }
#copy-btn:disabled { #copy-btn:disabled {
background: #05A700; background: #05a700;
border: 1px solid #05A700; border: 1px solid #05a700;
cursor: auto; cursor: auto;
} }
#delete-file { #delete-file {
width: 176px; width: 176px;
height: 44px; height: 44px;
background: #FFF; background: #fff;
border: 1px solid rgba(12, 12, 13, 0.3); border: 1px solid rgba(12, 12, 13, 0.3);
border-radius: 5px; border-radius: 5px;
font-size: 15px; font-size: 15px;
@ -322,7 +327,7 @@ tbody {
font-size: 15px; font-size: 15px;
margin: auto; margin: auto;
text-align: center; text-align: center;
color: #0094FB; color: #0094fb;
cursor: pointer; cursor: pointer;
text-decoration: underline; text-decoration: underline;
} }
@ -336,7 +341,8 @@ tbody {
text-align: center; text-align: center;
} }
#upload-error[hidden], #unsupported-browser[hidden] { #upload-error[hidden],
#unsupported-browser[hidden] {
display: none; display: none;
} }
@ -358,7 +364,7 @@ tbody {
line-height: 23px; line-height: 23px;
width: 630px; width: 630px;
text-align: center; text-align: center;
color: #7D7D7D; color: #7d7d7d;
margin: 0 auto 23px; margin: 0 auto 23px;
} }
@ -370,14 +376,14 @@ tbody {
margin-bottom: 181px; margin-bottom: 181px;
width: 260px; width: 260px;
height: 80px; height: 80px;
background: #12BC00; background: #12bc00;
border-radius: 3px; border-radius: 3px;
cursor: pointer; cursor: pointer;
border: 0; border: 0;
box-shadow: 0 5px 3px rgb(234, 234, 234); box-shadow: 0 5px 3px rgb(234, 234, 234);
font-family: 'Fira Sans'; font-family: 'Fira Sans';
font-weight: 500; font-weight: 500;
color: #FFF; color: #fff;
font-size: 26px; font-size: 26px;
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -406,15 +412,15 @@ tbody {
margin-top: 20px; margin-top: 20px;
margin-bottom: 30px; margin-bottom: 30px;
text-align: center; text-align: center;
background: #0297F8; background: #0297f8;
border: 1px solid #0297F8; border: 1px solid #0297f8;
border-radius: 5px; border-radius: 5px;
font-weight: 300; font-weight: 300;
cursor: pointer; cursor: pointer;
} }
#download-btn:disabled { #download-btn:disabled {
background: #47B04B; background: #47b04b;
cursor: auto; cursor: auto;
} }
@ -436,7 +442,7 @@ tbody {
line-height: 23px; line-height: 23px;
width: 630px; width: 630px;
text-align: center; text-align: center;
color: #7D7D7D; color: #7d7d7d;
margin: 0 auto 23px; margin: 0 auto 23px;
} }
@ -495,7 +501,8 @@ tbody {
margin-left: 30px; margin-left: 30px;
} }
.github, .twitter { .github,
.twitter {
width: 32px; width: 32px;
height: 32px; height: 32px;
margin-bottom: -5px; margin-bottom: -5px;

View File

@ -39,7 +39,7 @@ const conf = convict({
}, },
max_file_size: { max_file_size: {
format: Number, format: Number,
default: (1024 * 1024 * 1024) * 2, default: 1024 * 1024 * 1024 * 2,
env: 'P2P_MAX_FILE_SIZE' env: 'P2P_MAX_FILE_SIZE'
} }
}); });

View File

@ -34,10 +34,12 @@ app.engine(
app.set('view engine', 'handlebars'); app.set('view engine', 'handlebars');
app.use(helmet()); app.use(helmet());
app.use(helmet.hsts({ app.use(
helmet.hsts({
maxAge: 31536000, maxAge: 31536000,
force: conf.env === 'production' force: conf.env === 'production'
})); })
);
app.use( app.use(
helmet.contentSecurityPolicy({ helmet.contentSecurityPolicy({
directives: { directives: {
@ -62,11 +64,13 @@ app.use(
} }
}) })
); );
app.use(busboy({ app.use(
busboy({
limits: { limits: {
fileSize: conf.max_file_size fileSize: conf.max_file_size
} }
})); })
);
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(express.static(STATIC_PATH)); app.use(express.static(STATIC_PATH));
app.use('/l20n', express.static(L20N)); app.use('/l20n', express.static(L20N));
@ -112,16 +116,14 @@ app.get('/download/:id', (req, res) => {
storage storage
.length(id) .length(id)
.then(contentLength => { .then(contentLength => {
storage storage.ttl(id).then(timeToExpiry => {
.ttl(id)
.then(timeToExpiry => {
res.render('download', { res.render('download', {
filename: decodeURIComponent(filename), filename: decodeURIComponent(filename),
filesize: bytes(contentLength), filesize: bytes(contentLength),
sizeInBytes: contentLength, sizeInBytes: contentLength,
timeToExpiry: timeToExpiry timeToExpiry: timeToExpiry
}); });
}) });
}) })
.catch(() => { .catch(() => {
res.status(404).render('notfound'); res.status(404).render('notfound');
@ -228,7 +230,8 @@ app.post('/upload', (req, res, next) => {
req.busboy.on('file', (fieldname, file, filename) => { req.busboy.on('file', (fieldname, file, filename) => {
log.info('Uploading:', newId); log.info('Uploading:', newId);
storage.set(newId, file, filename, meta).then(() => { storage.set(newId, file, filename, meta).then(
() => {
const protocol = conf.env === 'production' ? 'https' : req.protocol; const protocol = conf.env === 'production' ? 'https' : req.protocol;
const url = `${protocol}://${req.get('host')}/download/${newId}/`; const url = `${protocol}://${req.get('host')}/download/${newId}/`;
res.json({ res.json({
@ -242,7 +245,8 @@ app.post('/upload', (req, res, next) => {
return res.sendStatus(413); return res.sendStatus(413);
} }
res.sendStatus(500); res.sendStatus(500);
}); }
);
}); });
req.on('close', err => { req.on('close', err => {
@ -256,7 +260,7 @@ app.post('/upload', (req, res, next) => {
.catch(err => { .catch(err => {
log.info('DeleteError:', newId); log.info('DeleteError:', newId);
}); });
}) });
}); });
app.get('/__lbheartbeat__', (req, res) => { app.get('/__lbheartbeat__', (req, res) => {

View File

@ -83,8 +83,8 @@ function ttl(id) {
} else { } else {
reject(err); reject(err);
} }
}) });
}) });
} }
function filename(id) { function filename(id) {
@ -235,8 +235,8 @@ function awsSet(newId, file, filename, meta) {
hitLimit = true; hitLimit = true;
upload.abort(); upload.abort();
}); });
return upload.promise() return upload.promise().then(
.then(() => { () => {
redis_client.hmset(newId, meta); redis_client.hmset(newId, meta);
redis_client.expire(newId, 86400000); redis_client.expire(newId, 86400000);
log.info('awsUploadFinish', 'Upload Finished of ' + filename); log.info('awsUploadFinish', 'Upload Finished of ' + filename);
@ -247,7 +247,8 @@ function awsSet(newId, file, filename, meta) {
} else { } else {
throw err; throw err;
} }
}); }
);
} }
function awsDelete(id, delete_token) { function awsDelete(id, delete_token) {