/* global EXPIRE_SECONDS */ const html = require('choo/html'); const raw = require('choo/html/raw'); const assets = require('../../../common/assets'); const notFound = require('../notFound'); const changePasswordSection = require('../../templates/changePasswordSection'); const setPasswordSection = require('../../templates/setPasswordSection'); const selectbox = require('../../templates/selectbox'); const deletePopup = require('../../templates/popup'); const { allowedCopy, delay, fadeOut } = require('../../utils'); function expireInfo(file, translate, emit) { const hours = Math.floor(EXPIRE_SECONDS / 60 / 60); const el = html`
${raw( translate('expireInfo', { downloadCount: '', timespan: translate('timespanHours', { num: hours }) }) )}
`; const select = el.querySelector('select'); const options = [1, 2, 3, 4, 5, 20].filter(i => i > (file.dtotal || 0)); const t = num => translate('downloadCount', { num }); const changed = value => emit('changeLimit', { file, value }); select.parentNode.replaceChild( selectbox(file.dlimit || 1, options, t, changed), select ); return el; } module.exports = function(state, emit) { const file = state.storage.getFileById(state.params.id); if (!file) { return notFound(state, emit); } const passwordSection = file.hasPassword ? changePasswordSection(state, emit) : setPasswordSection(state, emit); const div = html`
${expireInfo(file, state.translate, emit)}
${state.translate('copyUrlFormLabelWithName', { filename: file.name })}
${passwordSection}
${deletePopup( state.translate('deletePopupText'), state.translate('deletePopupYes'), state.translate('deletePopupCancel'), deleteFile )}
${state.translate('sendAnotherFileLink')}
`; function showPopup() { const popup = document.querySelector('.popup'); popup.classList.add('popup--show'); popup.focus(); } async function sendNew(e) { e.preventDefault(); await fadeOut('#shareWrapper'); emit('pushState', '/'); } 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('inputBtn--copied'); copyBtn.replaceChild( html``, copyBtn.firstChild ); await delay(2000); input.disabled = false; copyBtn.disabled = false; copyBtn.classList.remove('inputBtn--copied'); copyBtn.textContent = state.translate('copyUrlFormButton'); } } async function deleteFile() { emit('delete', { file, location: 'success-screen' }); await fadeOut('#shareWrapper'); emit('pushState', '/'); } return div; };