2018-10-25 02:07:10 +00:00
|
|
|
/* global downloadMetadata */
|
|
|
|
const html = require('choo/html');
|
|
|
|
const archiveTile = require('./archiveTile');
|
2019-02-27 19:42:43 +00:00
|
|
|
const assets = require('../../common/assets');
|
2019-01-15 18:11:51 +00:00
|
|
|
const modal = require('./modal');
|
2019-01-08 19:24:07 +00:00
|
|
|
const notFound = require('./notFound');
|
2018-10-25 02:07:10 +00:00
|
|
|
|
|
|
|
function password(state, emit) {
|
|
|
|
const fileInfo = state.fileInfo;
|
|
|
|
const invalid = fileInfo.password === null;
|
|
|
|
|
|
|
|
const div = html`
|
2018-11-16 20:39:36 +00:00
|
|
|
<div
|
2019-02-26 23:38:55 +00:00
|
|
|
class="h-full w-full flex flex-col items-center justify-center bg-white py-8 max-w-md mx-auto"
|
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-02-26 23:06:50 +00:00
|
|
|
<p
|
|
|
|
class="w-full mb-4 md:w-4/5 font-light text-center text-grey-darkest leading-normal"
|
|
|
|
>
|
2019-02-22 20:42:10 +00:00
|
|
|
${state.translate('downloadMessage')}
|
|
|
|
</p>
|
2019-01-30 15:50:17 +00:00
|
|
|
<form
|
|
|
|
class="flex flex-row flex-no-wrap w-full md:w-4/5"
|
|
|
|
onsubmit="${checkPassword}"
|
|
|
|
data-no-csrf
|
2018-11-16 20:39:36 +00:00
|
|
|
>
|
|
|
|
<input
|
|
|
|
id="password-input"
|
2019-02-15 22:42:09 +00:00
|
|
|
class="w-full border-l border-t border-b rounded-l-lg rounded-r-none ${invalid
|
2019-01-24 20:31:20 +00:00
|
|
|
? 'border-red'
|
|
|
|
: 'border-grey'} leading-loose px-2 py-1"
|
2018-10-30 21:00:37 +00:00
|
|
|
maxlength="32"
|
2018-10-25 02:07:10 +00:00
|
|
|
autocomplete="off"
|
|
|
|
placeholder="${state.translate('unlockInputPlaceholder')}"
|
2018-11-16 20:39:36 +00:00
|
|
|
oninput="${inputChanged}"
|
|
|
|
type="password"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="submit"
|
2018-10-25 02:07:10 +00:00
|
|
|
id="password-btn"
|
2019-02-15 22:42:09 +00:00
|
|
|
class="btn rounded-r-lg rounded-l-none ${invalid
|
2019-01-30 15:50:17 +00:00
|
|
|
? 'bg-red hover:bg-red focus:bg-red'
|
|
|
|
: ''}"
|
|
|
|
value="${state.translate('unlockButtonLabel')}"
|
2019-02-21 03:59:29 +00:00
|
|
|
title="${state.translate('unlockButtonLabel')}"
|
2018-11-16 20:39:36 +00:00
|
|
|
/>
|
2018-10-25 02:07:10 +00:00
|
|
|
</form>
|
2019-01-30 15:50:17 +00:00
|
|
|
<label
|
|
|
|
id="password-error"
|
|
|
|
class="${invalid ? '' : 'invisible'} text-red my-4"
|
|
|
|
for="password-input"
|
|
|
|
>
|
|
|
|
${state.translate('passwordTryAgain')}
|
|
|
|
</label>
|
2018-11-16 20:39:36 +00:00
|
|
|
</div>
|
|
|
|
`;
|
2018-10-25 02:07:10 +00:00
|
|
|
|
|
|
|
if (!(div instanceof String)) {
|
|
|
|
setTimeout(() => document.getElementById('password-input').focus());
|
|
|
|
}
|
|
|
|
|
2019-01-30 15:50:17 +00:00
|
|
|
function inputChanged(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2018-10-30 21:00:37 +00:00
|
|
|
const label = document.getElementById('password-error');
|
|
|
|
const input = document.getElementById('password-input');
|
2019-01-30 15:50:17 +00:00
|
|
|
const btn = document.getElementById('password-btn');
|
2018-10-30 21:00:37 +00:00
|
|
|
label.classList.add('invisible');
|
|
|
|
input.classList.remove('border-red');
|
2019-01-30 15:50:17 +00:00
|
|
|
btn.classList.remove('bg-red', 'hover:bg-red', 'focus:bg-red');
|
2018-10-25 02:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkPassword(event) {
|
2019-01-30 15:50:17 +00:00
|
|
|
event.stopPropagation();
|
2018-10-25 02:07:10 +00:00
|
|
|
event.preventDefault();
|
2019-02-20 19:51:09 +00:00
|
|
|
const el = document.getElementById('password-input');
|
|
|
|
const password = el.value;
|
2018-10-25 02:07:10 +00:00
|
|
|
if (password.length > 0) {
|
|
|
|
document.getElementById('password-btn').disabled = true;
|
|
|
|
state.fileInfo.url = window.location.href;
|
|
|
|
state.fileInfo.password = password;
|
|
|
|
emit('getMetadata');
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createFileInfo(state) {
|
|
|
|
return {
|
|
|
|
id: state.params.id,
|
|
|
|
secretKey: state.params.key,
|
|
|
|
nonce: downloadMetadata.nonce,
|
|
|
|
requiresPassword: downloadMetadata.pwd
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-30 15:50:17 +00:00
|
|
|
content = html`
|
2019-02-26 22:52:37 +00:00
|
|
|
<div
|
|
|
|
class="flex flex-col w-full h-full items-center md:justify-center md:-mt-8"
|
|
|
|
>
|
2019-01-30 15:50:17 +00:00
|
|
|
<h1 class="mb-4">${state.translate('downloadingTitle')}</h1>
|
|
|
|
${archiveTile.downloading(state, emit)}
|
|
|
|
</div>
|
|
|
|
`;
|
2018-10-25 02:07:10 +00:00
|
|
|
break;
|
|
|
|
case 'complete':
|
2018-10-30 21:00:37 +00:00
|
|
|
content = html`
|
2018-11-16 20:39:36 +00:00
|
|
|
<div
|
|
|
|
id="download-complete"
|
2019-02-22 15:42:08 +00:00
|
|
|
class="flex flex-col items-center justify-center h-full w-full bg-white p-2"
|
2018-11-16 20:39:36 +00:00
|
|
|
>
|
|
|
|
<h1 class="text-center font-bold my-4 text-2xl">
|
|
|
|
${state.translate('downloadFinish')}
|
|
|
|
</h1>
|
2019-02-26 22:52:37 +00:00
|
|
|
<p class="pb-2 text-grey-darkest leading-normal">
|
|
|
|
${state.translate('downloadFinishText')}
|
|
|
|
</p>
|
2019-02-27 19:42:43 +00:00
|
|
|
<img src="${assets.get('completed.svg')}" class="" />
|
2018-11-16 20:39:36 +00:00
|
|
|
<p class="mb-4">
|
2019-01-11 09:15:03 +00:00
|
|
|
<a
|
|
|
|
href="/"
|
2019-02-22 15:42:08 +00:00
|
|
|
class="btn rounded-lg flex items-center mt-4"
|
|
|
|
role="button"
|
2018-11-16 20:39:36 +00:00
|
|
|
>${state.translate('sendYourFilesLink')}</a
|
|
|
|
>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
`;
|
2018-10-25 02:07:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-01-30 15:50:17 +00:00
|
|
|
content = html`
|
2019-02-27 00:03:12 +00:00
|
|
|
<div
|
|
|
|
class="flex flex-col w-full max-w-md h-full mx-auto items-center justify-center"
|
|
|
|
>
|
2019-02-22 15:42:08 +00:00
|
|
|
<h1 class="mb-4">${state.translate('downloadFilesTitle')}</h1>
|
2019-02-26 22:52:37 +00:00
|
|
|
<p
|
|
|
|
class="w-full md:w-4/5 font-light text-grey-darkest text-center leading-normal"
|
|
|
|
>
|
2019-02-22 19:13:31 +00:00
|
|
|
${state.translate('downloadMessage')}
|
2019-02-22 15:42:08 +00:00
|
|
|
</p>
|
2019-01-30 15:50:17 +00:00
|
|
|
${archiveTile.preview(state, emit)}
|
|
|
|
</div>
|
|
|
|
`;
|
2018-10-25 02:07:10 +00:00
|
|
|
}
|
|
|
|
} else if (state.fileInfo.requiresPassword && !state.fileInfo.password) {
|
|
|
|
content = password(state, emit);
|
|
|
|
}
|
|
|
|
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
|
|
|
};
|