/* global EXPIRE_SECONDS */ const html = require('choo/html'); const raw = require('choo/html/raw'); const assets = require('../../../common/assets'); const notFound = require('../notFound'); const deletePopup = require('../../templates/popup'); const uploadedFiles = require('../../templates/uploadedFileList'); const { allowedCopy, delay, fadeOut } = require('../../utils'); module.exports = function(state, emit) { const file = state.storage.getFileById(state.params.id); if (!file) { return notFound(state); } const passwordReminderClass = file._hasPassword ? '' : 'passwordReminder--hidden'; const multifiles = Array.from(file.manifest.files); return html`
${expireInfo(file, state.translate)} ${uploadedFiles(multifiles, state, emit)}
${state.translate('copyUrlFormLabelWithName', { filename: '' })}
(don't forget the password too)
${deletePopup( state.translate('deletePopupText'), state.translate('deletePopupYes'), state.translate('deletePopupCancel'), deleteFile )}
${state.translate('deleteFileButton')}
`; function showPopup() { const popup = document.querySelector('.popup'); popup.classList.add('popup--show'); popup.focus(); } async function copyLink() { if (allowedCopy()) { emit('copy', { url: file.url, location: 'success-screen' }); const input = document.getElementById('fileUrl'); input.disabled = true; const copyBtn = document.getElementById('copyBtn'); copyBtn.disabled = true; copyBtn.classList.add('copyBtn--copied'); copyBtn.replaceChild( html``, copyBtn.firstChild ); await delay(2000); input.disabled = false; copyBtn.disabled = false; copyBtn.classList.remove('copyBtn--copied'); copyBtn.textContent = state.translate('copyUrlFormButton'); } } async function deleteFile() { emit('delete', { file, location: 'success-screen' }); await fadeOut('#shareWrapper'); emit('pushState', '/'); } }; function expireInfo(file, translate) { const hours = Math.floor(EXPIRE_SECONDS / 60 / 60); const el = html`
${raw( translate('expireInfo', { downloadCount: translate('downloadCount', { num: file.dlimit }), timespan: translate('timespanHours', { num: hours }) }) )}
`; return el; }