const html = require('choo/html'); const assets = require('../../common/assets'); const notFound = require('./notFound'); const downloadPassword = require('./downloadPassword'); const { bytes } = require('../utils'); function getFileFromDOM() { const el = document.getElementById('dl-file'); if (!el) { return null; } return { nonce: el.getAttribute('data-nonce'), pwd: !!+el.getAttribute('data-requires-password') }; } 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.secretKey = state.params.key; const fileInfo = state.fileInfo; const size = fileInfo.size ? state.translate('downloadFileSize', { size: bytes(fileInfo.size) }) : ''; let action = html`
${state.translate('downloadAltText')}
`; 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'); const div = html`
${title} ${' ' + size}
${state.translate('downloadMessage')}
${action}
${state.translate('sendYourFilesLink')}
`; function download(event) { event.preventDefault(); emit('download', fileInfo); } return div; };