2017-07-24 22:07:49 +02:00
|
|
|
/* global MAXFILESIZE EXPIRE_SECONDS */
|
2017-08-05 21:23:58 +02:00
|
|
|
const { Raven } = require('./common');
|
2017-06-02 05:59:27 +02:00
|
|
|
const FileSender = require('./fileSender');
|
2017-08-03 23:07:22 +02:00
|
|
|
const {
|
2017-08-06 03:06:43 +02:00
|
|
|
bytes,
|
2017-08-04 05:13:17 +02:00
|
|
|
copyToClipboard,
|
2017-08-03 23:07:22 +02:00
|
|
|
notify,
|
|
|
|
gcmCompliant,
|
|
|
|
ONE_DAY_IN_MS
|
|
|
|
} = require('./utils');
|
2017-07-21 21:44:55 +02:00
|
|
|
const Storage = require('./storage');
|
|
|
|
const storage = new Storage(localStorage);
|
2017-08-05 21:23:58 +02:00
|
|
|
const metrics = require('./metrics');
|
2017-08-06 03:06:43 +02:00
|
|
|
const progress = require('./progress');
|
2017-07-21 22:36:26 +02:00
|
|
|
|
2017-06-08 22:45:28 +02:00
|
|
|
const $ = require('jquery');
|
2017-06-02 00:10:00 +02:00
|
|
|
|
2017-08-03 16:11:23 +02:00
|
|
|
const allowedCopy = () => {
|
|
|
|
const support = !!document.queryCommandSupported;
|
|
|
|
return support ? document.queryCommandSupported('copy') : false;
|
2017-08-04 23:44:11 +02:00
|
|
|
};
|
2017-08-03 16:11:23 +02:00
|
|
|
|
2017-08-04 22:41:06 +02:00
|
|
|
$(() => {
|
2017-08-03 23:07:22 +02:00
|
|
|
gcmCompliant()
|
2017-08-05 21:23:58 +02:00
|
|
|
.then(function() {
|
2017-08-04 22:41:06 +02:00
|
|
|
const $pageOne = $('#page-one');
|
|
|
|
const $copyBtn = $('#copy-btn');
|
|
|
|
const $link = $('#link');
|
|
|
|
const $uploadWindow = $('.upload-window');
|
|
|
|
const $uploadError = $('#upload-error');
|
|
|
|
const $uploadProgress = $('#upload-progress');
|
|
|
|
const $fileList = $('#file-list');
|
|
|
|
|
|
|
|
$pageOne.removeAttr('hidden');
|
|
|
|
$('#file-upload').on('change', onUpload);
|
|
|
|
|
2017-08-05 21:23:58 +02:00
|
|
|
$(document.body).on('dragover', allowDrop).on('drop', onUpload);
|
2017-08-04 22:41:06 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
// reset copy button
|
2017-08-04 22:41:06 +02:00
|
|
|
$copyBtn.attr({
|
|
|
|
disabled: !allowedCopy(),
|
|
|
|
'data-l10n-id': 'copyUrlFormButton'
|
2017-08-05 21:23:58 +02:00
|
|
|
});
|
2017-08-04 22:41:06 +02:00
|
|
|
|
|
|
|
$link.attr('disabled', false);
|
|
|
|
|
|
|
|
const toggleHeader = () => {
|
|
|
|
//hide table header if empty list
|
|
|
|
if (document.querySelector('tbody').childNodes.length === 1) {
|
|
|
|
$fileList.attr('hidden', true);
|
|
|
|
} else {
|
|
|
|
$fileList.removeAttr('hidden');
|
|
|
|
}
|
2017-08-05 21:23:58 +02:00
|
|
|
};
|
2017-08-03 23:07:22 +02:00
|
|
|
|
|
|
|
const files = storage.files;
|
|
|
|
if (files.length === 0) {
|
|
|
|
toggleHeader();
|
|
|
|
} else {
|
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
for (let index in files) {
|
|
|
|
const id = files[index].fileId;
|
|
|
|
//check if file still exists before adding to list
|
|
|
|
checkExistence(id, files[index], true);
|
|
|
|
}
|
2017-07-24 21:42:16 +02:00
|
|
|
}
|
2017-08-03 23:07:22 +02:00
|
|
|
|
|
|
|
// copy link to clipboard
|
2017-08-04 22:41:06 +02:00
|
|
|
$copyBtn.on('click', () => {
|
|
|
|
if (allowedCopy() && copyToClipboard($link.attr('value'))) {
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics.copiedLink({ location: 'success-screen' });
|
2017-08-04 22:41:06 +02:00
|
|
|
|
2017-08-04 23:44:11 +02:00
|
|
|
//disable button for 3s
|
|
|
|
$copyBtn.attr('disabled', true);
|
2017-08-04 22:41:06 +02:00
|
|
|
$link.attr('disabled', true);
|
2017-08-04 23:44:11 +02:00
|
|
|
$copyBtn.html(
|
|
|
|
'<img src="/resources/check-16.svg" class="icon-check"></img>'
|
|
|
|
);
|
2017-08-04 22:41:06 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
$copyBtn.attr({
|
|
|
|
disabled: false,
|
|
|
|
'data-l10n-id': 'copyUrlFormButton'
|
|
|
|
});
|
|
|
|
$link.attr('disabled', false);
|
2017-08-04 23:44:11 +02:00
|
|
|
}, 3000);
|
|
|
|
}
|
2017-07-21 22:25:08 +02:00
|
|
|
});
|
2017-07-18 19:52:32 +02:00
|
|
|
|
2017-08-05 21:23:58 +02:00
|
|
|
$uploadWindow
|
|
|
|
.on('dragover', () => {
|
|
|
|
$uploadWindow.addClass('ondrag');
|
|
|
|
})
|
|
|
|
.on('dragleave', () => {
|
|
|
|
$uploadWindow.removeClass('ondrag');
|
|
|
|
});
|
2017-08-04 22:41:06 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
//link back to homepage
|
|
|
|
$('.send-new').attr('href', window.location);
|
|
|
|
|
|
|
|
// on file upload by browse or drag & drop
|
|
|
|
function onUpload(event) {
|
|
|
|
event.preventDefault();
|
2017-08-05 21:23:58 +02:00
|
|
|
const clickOrDrop = event.type === 'drop' ? 'drop' : 'click';
|
2017-07-11 22:30:25 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
// don't allow upload if not on upload page
|
2017-08-04 22:41:06 +02:00
|
|
|
if ($pageOne.attr('hidden')) {
|
2017-08-03 23:07:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.totalUploads += 1;
|
|
|
|
|
|
|
|
let file = '';
|
2017-08-05 21:23:58 +02:00
|
|
|
if (clickOrDrop === 'drop') {
|
2017-08-03 23:07:22 +02:00
|
|
|
if (!event.originalEvent.dataTransfer.files[0]) {
|
2017-08-04 22:41:06 +02:00
|
|
|
$uploadWindow.removeClass('ondrag');
|
2017-08-03 23:07:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
event.originalEvent.dataTransfer.files.length > 1 ||
|
|
|
|
event.originalEvent.dataTransfer.files[0].size === 0
|
|
|
|
) {
|
2017-08-04 22:41:06 +02:00
|
|
|
$uploadWindow.removeClass('ondrag');
|
2017-08-03 23:07:22 +02:00
|
|
|
document.l10n
|
|
|
|
.formatValue('uploadPageMultipleFilesAlert')
|
|
|
|
.then(str => {
|
|
|
|
alert(str);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
file = event.originalEvent.dataTransfer.files[0];
|
|
|
|
} else {
|
|
|
|
file = event.target.files[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file.size > MAXFILESIZE) {
|
|
|
|
return document.l10n
|
|
|
|
.formatValue('fileTooBig', { size: bytes(MAXFILESIZE) })
|
|
|
|
.then(alert);
|
|
|
|
}
|
|
|
|
|
2017-08-04 22:41:06 +02:00
|
|
|
$pageOne.attr('hidden', true);
|
|
|
|
$uploadError.attr('hidden', true);
|
|
|
|
$uploadProgress.removeAttr('hidden');
|
2017-08-06 03:06:43 +02:00
|
|
|
document.l10n
|
|
|
|
.formatValue('uploadingPageProgress', {
|
|
|
|
size: bytes(file.size),
|
|
|
|
filename: file.name
|
|
|
|
})
|
|
|
|
.then(str => {
|
|
|
|
$('#upload-filename').text(str);
|
|
|
|
});
|
|
|
|
document.l10n.formatValue('importingFile').then(progress.setText);
|
2017-08-03 23:07:22 +02:00
|
|
|
//don't allow drag and drop when not on page-one
|
2017-08-04 22:41:06 +02:00
|
|
|
$(document.body).off('drop', onUpload);
|
2017-07-21 00:16:00 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
const fileSender = new FileSender(file);
|
2017-08-04 22:41:06 +02:00
|
|
|
$('#cancel-upload').on('click', () => {
|
2017-08-03 23:07:22 +02:00
|
|
|
fileSender.cancel();
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics.cancelledUpload({
|
|
|
|
size: file.size,
|
|
|
|
type: clickOrDrop
|
2017-07-24 07:26:06 +02:00
|
|
|
});
|
2017-08-03 23:07:22 +02:00
|
|
|
location.reload();
|
|
|
|
});
|
2017-07-24 07:26:06 +02:00
|
|
|
|
2017-08-06 03:06:43 +02:00
|
|
|
let uploadStart;
|
|
|
|
fileSender.on('progress', data => {
|
|
|
|
uploadStart = uploadStart || Date.now();
|
|
|
|
progress.setProgress({
|
|
|
|
complete: data[0],
|
|
|
|
total: data[1]
|
2017-08-04 22:41:06 +02:00
|
|
|
});
|
2017-08-03 23:07:22 +02:00
|
|
|
});
|
|
|
|
|
2017-08-06 03:06:43 +02:00
|
|
|
fileSender.on('hashing', () => {
|
|
|
|
document.l10n.formatValue('verifyingFile').then(progress.setText);
|
2017-07-21 22:25:08 +02:00
|
|
|
});
|
2017-08-03 23:07:22 +02:00
|
|
|
|
2017-08-06 03:06:43 +02:00
|
|
|
fileSender.on('encrypting', () => {
|
|
|
|
document.l10n.formatValue('encryptingFile').then(progress.setText);
|
2017-08-03 23:07:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let t;
|
|
|
|
const startTime = Date.now();
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics.startedUpload({
|
|
|
|
size: file.size,
|
|
|
|
type: clickOrDrop
|
2017-08-03 23:07:22 +02:00
|
|
|
});
|
|
|
|
// For large files we need to give the ui a tick to breathe and update
|
|
|
|
// before we kick off the FileSender
|
|
|
|
setTimeout(() => {
|
|
|
|
fileSender
|
|
|
|
.upload()
|
|
|
|
.then(info => {
|
|
|
|
const endTime = Date.now();
|
2017-08-05 21:23:58 +02:00
|
|
|
const time = endTime - startTime;
|
2017-08-03 23:07:22 +02:00
|
|
|
const uploadTime = endTime - uploadStart;
|
2017-08-05 21:23:58 +02:00
|
|
|
const speed = file.size / (uploadTime / 1000);
|
2017-08-03 23:07:22 +02:00
|
|
|
const expiration = EXPIRE_SECONDS * 1000;
|
|
|
|
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics.completedUpload({
|
|
|
|
size: file.size,
|
|
|
|
time,
|
|
|
|
speed,
|
|
|
|
type: clickOrDrop
|
2017-08-03 23:07:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const fileData = {
|
|
|
|
name: file.name,
|
|
|
|
size: file.size,
|
|
|
|
fileId: info.fileId,
|
|
|
|
url: info.url,
|
|
|
|
secretKey: info.secretKey,
|
|
|
|
deleteToken: info.deleteToken,
|
|
|
|
creationDate: new Date(),
|
|
|
|
expiry: expiration,
|
2017-08-05 21:23:58 +02:00
|
|
|
totalTime: time,
|
|
|
|
typeOfUpload: clickOrDrop,
|
|
|
|
uploadSpeed: speed
|
2017-08-03 23:07:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
storage.addFile(info.fileId, fileData);
|
2017-08-06 03:06:43 +02:00
|
|
|
|
|
|
|
$pageOne.attr('hidden', true);
|
|
|
|
$uploadProgress.attr('hidden', true);
|
|
|
|
$uploadError.attr('hidden', true);
|
|
|
|
$('#share-link').removeAttr('hidden');
|
2017-08-03 23:07:22 +02:00
|
|
|
|
|
|
|
populateFileList(fileData);
|
|
|
|
document.l10n.formatValue('notifyUploadDone').then(str => {
|
|
|
|
notify(str);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
// err is 0 when coming from a cancel upload event
|
|
|
|
if (err === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// only show error page when the error is anything other than user cancelling the upload
|
|
|
|
Raven.captureException(err);
|
2017-08-04 22:41:06 +02:00
|
|
|
$pageOne.attr('hidden', true);
|
|
|
|
$uploadProgress.attr('hidden', true);
|
|
|
|
$uploadError.removeAttr('hidden');
|
2017-08-03 23:07:22 +02:00
|
|
|
window.clearTimeout(t);
|
|
|
|
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics.stoppedUpload({
|
|
|
|
size: file.size,
|
|
|
|
type: clickOrDrop,
|
|
|
|
err
|
2017-08-03 23:07:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
function allowDrop(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkExistence(id, file, populate) {
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
xhr.onreadystatechange = () => {
|
|
|
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
|
|
if (xhr.status === 200) {
|
|
|
|
if (populate) {
|
|
|
|
populateFileList(file);
|
|
|
|
}
|
|
|
|
} else if (xhr.status === 404) {
|
|
|
|
storage.remove(id);
|
|
|
|
if (storage.numFiles === 0) {
|
|
|
|
toggleHeader();
|
|
|
|
}
|
|
|
|
}
|
2017-07-21 21:52:28 +02:00
|
|
|
}
|
2017-08-03 23:07:22 +02:00
|
|
|
};
|
|
|
|
xhr.open('get', '/exists/' + id, true);
|
|
|
|
xhr.send();
|
2017-06-30 01:08:57 +02:00
|
|
|
}
|
2017-06-01 19:54:17 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
//update file table with current files in storage
|
2017-08-05 21:23:58 +02:00
|
|
|
const populateFileList = file => {
|
2017-08-03 23:07:22 +02:00
|
|
|
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',
|
2017-08-04 23:44:11 +02:00
|
|
|
'data-l10n-id': 'copyUrlHover',
|
|
|
|
disabled: !allowedCopy()
|
2017-08-03 23:07:22 +02:00
|
|
|
});
|
|
|
|
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 popupDiv = document.createElement('div');
|
|
|
|
const $popupText = $('<div>', { class: 'popuptext' });
|
|
|
|
const cellText = document.createTextNode(file.name);
|
2017-07-19 20:35:11 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
const url = file.url.trim() + `#${file.secretKey}`.trim();
|
2017-08-05 21:23:58 +02:00
|
|
|
|
2017-08-04 22:41:06 +02:00
|
|
|
$link.attr('value', url);
|
|
|
|
$('#copy-text')
|
2017-08-06 03:06:43 +02:00
|
|
|
.attr('data-l10n-args', JSON.stringify({ filename: file.name }))
|
2017-08-04 22:41:06 +02:00
|
|
|
.attr('data-l10n-id', 'copyUrlFormLabelWithName');
|
2017-07-13 16:05:45 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
$popupText.attr('tabindex', '-1');
|
2017-06-02 00:10:00 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
name.appendChild(cellText);
|
2017-07-13 16:05:45 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
// create delete button
|
2017-07-19 00:46:44 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
const delSpan = document.createElement('span');
|
2017-08-04 22:41:06 +02:00
|
|
|
$(delSpan)
|
|
|
|
.addClass('icon-cancel-1')
|
|
|
|
.attr('data-l10n-id', 'deleteButtonHover');
|
2017-08-03 23:07:22 +02:00
|
|
|
del.appendChild(delSpan);
|
2017-07-19 00:46:44 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
const linkSpan = document.createElement('span');
|
2017-08-05 21:23:58 +02:00
|
|
|
$(linkSpan).addClass('icon-docs').attr('data-l10n-id', 'copyUrlHover');
|
2017-07-19 16:50:23 +02:00
|
|
|
|
2017-08-04 22:41:06 +02:00
|
|
|
link.appendChild(linkSpan);
|
2017-08-03 23:07:22 +02:00
|
|
|
link.style.color = '#0A8DFF';
|
2017-06-30 19:49:49 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
//copy link to clipboard when icon clicked
|
2017-08-04 22:41:06 +02:00
|
|
|
$copyIcon.on('click', () => {
|
2017-08-03 23:07:22 +02:00
|
|
|
// record copied event from upload list
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics.copiedLink({ location: 'upload-list' });
|
2017-08-04 05:13:17 +02:00
|
|
|
copyToClipboard(url);
|
2017-08-03 23:07:22 +02:00
|
|
|
document.l10n.formatValue('copiedUrl').then(translated => {
|
|
|
|
link.innerHTML = translated;
|
|
|
|
});
|
2017-08-04 22:41:06 +02:00
|
|
|
setTimeout(() => {
|
2017-08-03 23:07:22 +02:00
|
|
|
const linkImg = document.createElement('img');
|
2017-08-04 22:41:06 +02:00
|
|
|
$(linkImg)
|
|
|
|
.addClass('icon-copy')
|
|
|
|
.attr('data-l10n-id', 'copyUrlHover')
|
|
|
|
.attr('src', '/resources/copy-16.svg');
|
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
$(link).html(linkImg);
|
|
|
|
}, 500);
|
2017-07-22 02:01:26 +02:00
|
|
|
});
|
2017-07-21 00:16:00 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
file.creationDate = new Date(file.creationDate);
|
|
|
|
|
|
|
|
const future = new Date();
|
|
|
|
future.setTime(file.creationDate.getTime() + file.expiry);
|
|
|
|
|
|
|
|
let countdown = 0;
|
|
|
|
countdown = future.getTime() - Date.now();
|
|
|
|
let minutes = Math.floor(countdown / 1000 / 60);
|
|
|
|
let hours = Math.floor(minutes / 60);
|
|
|
|
let seconds = Math.floor(countdown / 1000 % 60);
|
|
|
|
|
2017-08-04 22:41:06 +02:00
|
|
|
const poll = () => {
|
2017-08-03 23:07:22 +02:00
|
|
|
countdown = future.getTime() - Date.now();
|
|
|
|
minutes = Math.floor(countdown / 1000 / 60);
|
|
|
|
hours = Math.floor(minutes / 60);
|
|
|
|
seconds = Math.floor(countdown / 1000 % 60);
|
|
|
|
let t;
|
|
|
|
|
|
|
|
if (hours >= 1) {
|
|
|
|
expiry.innerHTML = hours + 'h ' + minutes % 60 + 'm';
|
2017-08-04 22:41:06 +02:00
|
|
|
t = setTimeout(() => {
|
2017-08-03 23:07:22 +02:00
|
|
|
poll();
|
|
|
|
}, 60000);
|
|
|
|
} else if (hours === 0) {
|
|
|
|
expiry.innerHTML = minutes + 'm ' + seconds + 's';
|
|
|
|
t = window.setTimeout(() => {
|
|
|
|
poll();
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
//remove from list when expired
|
|
|
|
if (countdown <= 0) {
|
|
|
|
storage.remove(file.fileId);
|
|
|
|
$(expiry).parents('tr').remove();
|
|
|
|
window.clearTimeout(t);
|
|
|
|
toggleHeader();
|
|
|
|
}
|
2017-08-05 21:23:58 +02:00
|
|
|
};
|
2017-08-03 23:07:22 +02:00
|
|
|
|
2017-08-04 22:41:06 +02:00
|
|
|
poll();
|
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
// create popup
|
|
|
|
popupDiv.classList.add('popup');
|
|
|
|
const $popupMessage = $('<div>', { class: 'popup-message' });
|
|
|
|
$popupMessage.attr('data-l10n-id', 'deletePopupText');
|
|
|
|
const $popupAction = $('<div>', { class: 'popup-action' });
|
|
|
|
const $popupNvmSpan = $('<span>', { class: 'popup-no' });
|
|
|
|
$popupNvmSpan.attr('data-l10n-id', 'deletePopupCancel');
|
|
|
|
const $popupDelSpan = $('<span>', { class: 'popup-yes' });
|
|
|
|
$popupDelSpan.attr('data-l10n-id', 'deletePopupYes');
|
|
|
|
|
|
|
|
$popupText.html([$popupMessage, $popupAction]);
|
|
|
|
$popupAction.html([$popupNvmSpan, $popupDelSpan]);
|
|
|
|
|
|
|
|
// add data cells to table row
|
|
|
|
row.appendChild(name);
|
|
|
|
$(link).append($copyIcon);
|
|
|
|
row.appendChild(link);
|
|
|
|
row.appendChild(expiry);
|
|
|
|
$(popupDiv).append($popupText);
|
|
|
|
$(del).append($delIcon);
|
|
|
|
del.appendChild(popupDiv);
|
|
|
|
row.appendChild(del);
|
|
|
|
$('tbody').append(row); //add row to table
|
|
|
|
|
|
|
|
// delete file
|
2017-08-04 22:41:06 +02:00
|
|
|
$popupText.find('.popup-yes').on('click', e => {
|
2017-08-03 23:07:22 +02:00
|
|
|
FileSender.delete(file.fileId, file.deleteToken).then(() => {
|
|
|
|
$(e.target).parents('tr').remove();
|
2017-08-05 21:23:58 +02:00
|
|
|
const ttl =
|
2017-08-03 23:07:22 +02:00
|
|
|
ONE_DAY_IN_MS - (Date.now() - file.creationDate.getTime());
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics
|
|
|
|
.deletedUpload({
|
|
|
|
size: file.size,
|
|
|
|
time: file.totalTime,
|
|
|
|
speed: file.uploadSpeed,
|
|
|
|
type: file.typeOfUpload,
|
|
|
|
location: 'upload-list',
|
|
|
|
ttl
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
storage.remove(file.fileId);
|
|
|
|
});
|
2017-08-03 23:07:22 +02:00
|
|
|
toggleHeader();
|
|
|
|
});
|
2017-07-22 02:01:26 +02:00
|
|
|
});
|
2017-08-03 23:07:22 +02:00
|
|
|
|
2017-08-04 22:41:06 +02:00
|
|
|
$('#delete-file').on('click', () => {
|
2017-08-03 23:07:22 +02:00
|
|
|
FileSender.delete(file.fileId, file.deleteToken).then(() => {
|
2017-08-05 21:23:58 +02:00
|
|
|
const ttl =
|
2017-08-03 23:07:22 +02:00
|
|
|
ONE_DAY_IN_MS - (Date.now() - file.creationDate.getTime());
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics
|
|
|
|
.deletedUpload({
|
|
|
|
size: file.size,
|
|
|
|
time: file.totalTime,
|
|
|
|
speed: file.uploadSpeed,
|
|
|
|
type: file.typeOfUpload,
|
|
|
|
location: 'success-screen',
|
|
|
|
ttl
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
storage.remove(file.fileId);
|
|
|
|
location.reload();
|
|
|
|
});
|
2017-08-03 23:07:22 +02:00
|
|
|
});
|
2017-08-04 22:41:06 +02:00
|
|
|
});
|
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
// show popup
|
2017-08-04 22:41:06 +02:00
|
|
|
$delIcon.on('click', () => {
|
2017-08-05 21:23:58 +02:00
|
|
|
$popupText.addClass('show').focus();
|
2017-08-03 23:07:22 +02:00
|
|
|
});
|
2017-08-04 22:41:06 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
// hide popup
|
2017-08-04 22:41:06 +02:00
|
|
|
$popupText.find('.popup-no').on('click', e => {
|
2017-08-03 23:07:22 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
$popupText.removeClass('show');
|
|
|
|
});
|
2017-08-04 22:41:06 +02:00
|
|
|
|
|
|
|
$popupText.on('click', e => {
|
2017-08-03 23:07:22 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2017-08-04 22:41:06 +02:00
|
|
|
|
2017-08-03 23:07:22 +02:00
|
|
|
//close when popup loses focus
|
2017-08-04 22:41:06 +02:00
|
|
|
$popupText.on('blur', () => {
|
2017-08-03 23:07:22 +02:00
|
|
|
$popupText.removeClass('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
toggleHeader();
|
2017-08-05 21:23:58 +02:00
|
|
|
};
|
2017-08-03 23:07:22 +02:00
|
|
|
})
|
|
|
|
.catch(err => {
|
2017-08-05 21:23:58 +02:00
|
|
|
metrics.unsupported({ err }).then(() => {
|
2017-08-03 23:07:22 +02:00
|
|
|
location.replace('/unsupported/gcm');
|
2017-07-13 16:05:45 +02:00
|
|
|
});
|
2017-06-23 19:35:17 +02:00
|
|
|
});
|
2017-06-06 23:24:51 +02:00
|
|
|
});
|