2017-08-24 23:54:02 +02:00
|
|
|
const html = require('choo/html');
|
|
|
|
const assets = require('../../common/assets');
|
|
|
|
const notFound = require('./notFound');
|
2017-08-31 18:43:36 +02:00
|
|
|
const downloadPassword = require('./downloadPassword');
|
2017-08-24 23:54:02 +02:00
|
|
|
const { bytes } = require('../utils');
|
|
|
|
|
|
|
|
function getFileFromDOM() {
|
|
|
|
const el = document.getElementById('dl-file');
|
|
|
|
if (!el) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return {
|
2017-08-31 18:43:36 +02:00
|
|
|
nonce: el.getAttribute('data-nonce'),
|
|
|
|
pwd: !!+el.getAttribute('data-requires-password')
|
2017-08-24 23:54:02 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
|
|
|
state.fileInfo = state.fileInfo || getFileFromDOM();
|
|
|
|
if (!state.fileInfo) {
|
|
|
|
return notFound(state, emit);
|
|
|
|
}
|
|
|
|
state.fileInfo.id = state.params.id;
|
|
|
|
state.fileInfo.key = state.params.key;
|
|
|
|
const fileInfo = state.fileInfo;
|
2017-08-31 18:43:36 +02:00
|
|
|
const size = fileInfo.size
|
|
|
|
? state.translate('downloadFileSize', { size: bytes(fileInfo.size) })
|
|
|
|
: '';
|
|
|
|
let action = html`
|
|
|
|
<div>
|
|
|
|
<img src="${assets.get('illustration_download.svg')}"
|
|
|
|
id="download-img"
|
|
|
|
alt="${state.translate('downloadAltText')}"/>
|
|
|
|
<div>
|
|
|
|
<button id="download-btn"
|
|
|
|
class="btn"
|
|
|
|
onclick=${download}>${state.translate('downloadButtonLabel')}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
if (fileInfo.pwd && !fileInfo.password) {
|
|
|
|
action = downloadPassword(state, emit);
|
|
|
|
} else if (!state.transfer) {
|
|
|
|
emit('preview');
|
|
|
|
}
|
|
|
|
const title = fileInfo.name
|
|
|
|
? state.translate('downloadFileName', { filename: fileInfo.name })
|
|
|
|
: state.translate('downloadFileTitle');
|
2017-08-24 23:54:02 +02:00
|
|
|
const div = html`
|
|
|
|
<div id="page-one">
|
|
|
|
<div id="download">
|
|
|
|
<div id="download-page-one">
|
|
|
|
<div class="title">
|
|
|
|
<span id="dl-file"
|
2017-08-31 18:43:36 +02:00
|
|
|
data-nonce="${fileInfo.nonce}"
|
|
|
|
data-requires-password="${fileInfo.pwd}">${title}</span>
|
|
|
|
<span id="dl-filesize">${' ' + size}</span>
|
2017-08-24 23:54:02 +02:00
|
|
|
</div>
|
|
|
|
<div class="description">${state.translate('downloadMessage')}</div>
|
2017-08-31 18:43:36 +02:00
|
|
|
${action}
|
2017-08-24 23:54:02 +02:00
|
|
|
</div>
|
|
|
|
<a class="send-new" href="/">${state.translate('sendYourFilesLink')}</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
2017-08-31 18:43:36 +02:00
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
function download(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
emit('download', fileInfo);
|
|
|
|
}
|
|
|
|
return div;
|
|
|
|
};
|