2018-10-25 02:07:10 +00:00
|
|
|
/* global downloadMetadata */
|
|
|
|
const html = require('choo/html');
|
|
|
|
const archiveTile = require('./archiveTile');
|
2019-01-15 18:11:51 +00:00
|
|
|
const modal = require('./modal');
|
2019-02-28 22:28:18 +00:00
|
|
|
const noStreams = require('./noStreams');
|
2019-01-08 19:24:07 +00:00
|
|
|
const notFound = require('./notFound');
|
2019-02-28 22:28:18 +00:00
|
|
|
const downloadPassword = require('./downloadPassword');
|
|
|
|
const downloadCompleted = require('./downloadCompleted');
|
|
|
|
const BIG_SIZE = 1024 * 1024 * 256;
|
2018-10-25 02:07:10 +00:00
|
|
|
|
2019-02-28 22:28:18 +00:00
|
|
|
function createFileInfo(state) {
|
|
|
|
return {
|
|
|
|
id: state.params.id,
|
|
|
|
secretKey: state.params.key,
|
|
|
|
nonce: downloadMetadata.nonce,
|
|
|
|
requiresPassword: downloadMetadata.pwd
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloading(state, emit) {
|
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
class="flex flex-col w-full h-full items-center md:justify-center md:-mt-8"
|
|
|
|
>
|
|
|
|
<h1 class="mb-4">${state.translate('downloadingTitle')}</h1>
|
|
|
|
${archiveTile.downloading(state, emit)}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2018-10-25 02:07:10 +00:00
|
|
|
|
2019-02-28 22:28:18 +00:00
|
|
|
function preview(state, emit) {
|
|
|
|
if (!state.capabilities.streamDownload && state.fileInfo.size > BIG_SIZE) {
|
|
|
|
return noStreams(state, emit);
|
|
|
|
}
|
|
|
|
return html`
|
2018-11-16 20:39:36 +00:00
|
|
|
<div
|
2019-02-28 22:28:18 +00:00
|
|
|
class="flex flex-col w-full max-w-md h-full mx-auto items-center justify-center"
|
2018-11-16 20:39:36 +00:00
|
|
|
>
|
2019-02-22 15:42:08 +00:00
|
|
|
<h1 class="mb-4">${state.translate('downloadFilesTitle')}</h1>
|
2019-03-01 22:12:23 +00:00
|
|
|
<p class="w-full text-grey-darkest text-center leading-normal">
|
2019-02-22 20:42:10 +00:00
|
|
|
${state.translate('downloadMessage')}
|
|
|
|
</p>
|
2019-02-28 22:28:18 +00:00
|
|
|
${archiveTile.preview(state, emit)}
|
2018-11-16 20:39:36 +00:00
|
|
|
</div>
|
|
|
|
`;
|
2018-10-25 02:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
|
|
|
let content = '';
|
|
|
|
if (!state.fileInfo) {
|
|
|
|
state.fileInfo = createFileInfo(state);
|
2019-01-08 19:24:07 +00:00
|
|
|
if (!state.fileInfo.nonce) {
|
|
|
|
return notFound(state);
|
|
|
|
}
|
2018-10-25 02:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!state.transfer && !state.fileInfo.requiresPassword) {
|
|
|
|
emit('getMetadata');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.transfer) {
|
|
|
|
switch (state.transfer.state) {
|
|
|
|
case 'downloading':
|
|
|
|
case 'decrypting':
|
2019-02-28 22:28:18 +00:00
|
|
|
content = downloading(state, emit);
|
2018-10-25 02:07:10 +00:00
|
|
|
break;
|
|
|
|
case 'complete':
|
2019-02-28 22:28:18 +00:00
|
|
|
content = downloadCompleted(state);
|
2018-10-25 02:07:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-02-28 22:28:18 +00:00
|
|
|
content = preview(state, emit);
|
2018-10-25 02:07:10 +00:00
|
|
|
}
|
|
|
|
} else if (state.fileInfo.requiresPassword && !state.fileInfo.password) {
|
2019-02-28 22:28:18 +00:00
|
|
|
content = downloadPassword(state, emit);
|
2018-10-25 02:07:10 +00:00
|
|
|
}
|
|
|
|
return html`
|
2019-02-22 21:31:54 +00:00
|
|
|
<main class="main">
|
2019-01-15 18:11:51 +00:00
|
|
|
${state.modal && modal(state, emit)}
|
2019-02-22 00:43:15 +00:00
|
|
|
<section class="relative h-full w-full p-6 md:rounded-lg md:shadow-big">
|
2019-01-30 15:50:17 +00:00
|
|
|
${content}
|
2018-11-16 20:39:36 +00:00
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
`;
|
2018-10-25 02:07:10 +00:00
|
|
|
};
|