const html = require('choo/html'); const assets = require('../../common/assets'); const notFound = require('./notFound'); const { bytes } = require('../utils'); function getFileFromDOM() { const el = document.getElementById('dl-file'); if (!el) { return null; } const data = el.dataset; return { name: data.name, size: parseInt(data.size, 10), ttl: parseInt(data.ttl, 10) }; } 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; const size = bytes(fileInfo.size); const div = html`
${state.translate('downloadFileName', { filename: fileInfo.name })} ${' ' + state.translate('downloadFileSize', { size })}
${state.translate('downloadMessage')}
${state.translate('downloadAltText')}
${state.translate('sendYourFilesLink')}
`; function download(event) { event.preventDefault(); emit('download', fileInfo); } if (state.layout) { return state.layout(state, div); } return div; };