2018-10-25 04:07:10 +02:00
|
|
|
/* global downloadMetadata */
|
|
|
|
const html = require('choo/html');
|
2020-07-13 19:21:28 +02:00
|
|
|
const assets = require('../../common/assets');
|
2018-10-25 04:07:10 +02:00
|
|
|
const archiveTile = require('./archiveTile');
|
2019-01-15 19:11:51 +01:00
|
|
|
const modal = require('./modal');
|
2019-02-28 23:28:18 +01:00
|
|
|
const noStreams = require('./noStreams');
|
2019-01-08 20:24:07 +01:00
|
|
|
const notFound = require('./notFound');
|
2019-02-28 23:28:18 +01:00
|
|
|
const downloadPassword = require('./downloadPassword');
|
|
|
|
const downloadCompleted = require('./downloadCompleted');
|
|
|
|
const BIG_SIZE = 1024 * 1024 * 256;
|
2018-10-25 04:07:10 +02:00
|
|
|
|
2019-02-28 23:28:18 +01: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"
|
|
|
|
>
|
2019-06-14 20:30:43 +02:00
|
|
|
<h1 class="text-3xl font-bold mb-4">
|
|
|
|
${state.translate('downloadingTitle')}
|
|
|
|
</h1>
|
2019-02-28 23:28:18 +01:00
|
|
|
${archiveTile.downloading(state, emit)}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2018-10-25 04:07:10 +02:00
|
|
|
|
2019-02-28 23:28:18 +01:00
|
|
|
function preview(state, emit) {
|
2020-07-13 19:21:28 +02:00
|
|
|
if (state.fileInfo.flagged) {
|
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
class="flex flex-col w-full max-w-md h-full mx-auto items-center justify-center"
|
|
|
|
>
|
|
|
|
<h1 class="text-xl font-bold">${state.translate('downloadFlagged')}</h1>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2019-02-28 23:28:18 +01:00
|
|
|
if (!state.capabilities.streamDownload && state.fileInfo.size > BIG_SIZE) {
|
|
|
|
return noStreams(state, emit);
|
|
|
|
}
|
|
|
|
return html`
|
2020-07-25 03:11:50 +02:00
|
|
|
<div class="w-full md:flex md:flex-row items-stretch md:flex-1">
|
2020-07-13 19:21:28 +02:00
|
|
|
<div
|
|
|
|
class="px-2 w-full md:px-0 flex-half md:flex md:flex-col mt-12 md:pr-8 pb-4"
|
|
|
|
>
|
|
|
|
<h1 class="text-3xl font-bold mb-4 text-center md:text-left">
|
|
|
|
${state.translate('downloadTitle')}
|
|
|
|
</h1>
|
|
|
|
<p
|
|
|
|
class="text-grey-80 leading-normal dark:text-grey-40 mb-4 text-center md:text-left"
|
|
|
|
>
|
|
|
|
${state.translate('downloadDescription')}
|
|
|
|
</p>
|
|
|
|
<p
|
|
|
|
class="text-grey-80 leading-normal dark:text-grey-40 font-semibold text-center md:mb-8 md:text-left"
|
|
|
|
>
|
|
|
|
${state.translate('downloadConfirmDescription')}
|
|
|
|
</p>
|
|
|
|
<img
|
|
|
|
class="hidden md:block dl-bg w-full"
|
|
|
|
src="${assets.get('intro.svg')}"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
class="w-full flex-half flex-half md:flex md:flex-col md:justify-center"
|
2019-09-09 19:34:55 +02:00
|
|
|
>
|
2020-07-13 19:21:28 +02:00
|
|
|
${archiveTile.preview(state, emit)}
|
|
|
|
<a href="/report" class="link-blue mt-4 text-center block"
|
|
|
|
>${state.translate('reportFile', {
|
|
|
|
count: state.fileInfo.manifest.files.length
|
|
|
|
})}</a
|
|
|
|
>
|
|
|
|
</div>
|
2018-11-16 21:39:36 +01:00
|
|
|
</div>
|
|
|
|
`;
|
2018-10-25 04:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
|
|
|
let content = '';
|
|
|
|
if (!state.fileInfo) {
|
|
|
|
state.fileInfo = createFileInfo(state);
|
2019-01-08 20:24:07 +01:00
|
|
|
if (!state.fileInfo.nonce) {
|
|
|
|
return notFound(state);
|
|
|
|
}
|
2018-10-25 04:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!state.transfer && !state.fileInfo.requiresPassword) {
|
|
|
|
emit('getMetadata');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.transfer) {
|
|
|
|
switch (state.transfer.state) {
|
|
|
|
case 'downloading':
|
|
|
|
case 'decrypting':
|
2019-02-28 23:28:18 +01:00
|
|
|
content = downloading(state, emit);
|
2018-10-25 04:07:10 +02:00
|
|
|
break;
|
|
|
|
case 'complete':
|
2019-02-28 23:28:18 +01:00
|
|
|
content = downloadCompleted(state);
|
2018-10-25 04:07:10 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-02-28 23:28:18 +01:00
|
|
|
content = preview(state, emit);
|
2018-10-25 04:07:10 +02:00
|
|
|
}
|
|
|
|
} else if (state.fileInfo.requiresPassword && !state.fileInfo.password) {
|
2019-02-28 23:28:18 +01:00
|
|
|
content = downloadPassword(state, emit);
|
2018-10-25 04:07:10 +02:00
|
|
|
}
|
|
|
|
return html`
|
2019-02-22 22:31:54 +01:00
|
|
|
<main class="main">
|
2019-01-15 19:11:51 +01:00
|
|
|
${state.modal && modal(state, emit)}
|
2019-05-03 18:26:10 +02:00
|
|
|
<section
|
2020-07-27 20:18:52 +02:00
|
|
|
class="relative overflow-hidden h-full w-full p-6 md:p-8 md:rounded-xl md:shadow-big md:flex md:flex-col"
|
2019-05-03 18:26:10 +02:00
|
|
|
>
|
2019-01-30 16:50:17 +01:00
|
|
|
${content}
|
2018-11-16 21:39:36 +01:00
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
`;
|
2018-10-25 04:07:10 +02:00
|
|
|
};
|