2017-12-14 02:22:17 +00:00
|
|
|
/* global EXPIRE_SECONDS */
|
2017-08-24 21:54:02 +00:00
|
|
|
const html = require('choo/html');
|
2018-02-11 22:02:40 +00:00
|
|
|
const raw = require('choo/html/raw');
|
2018-02-13 19:32:59 +00:00
|
|
|
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');
|
2017-08-24 21:54:02 +00:00
|
|
|
|
2017-11-30 21:41:09 +00:00
|
|
|
function expireInfo(file, translate, emit) {
|
2017-12-14 02:22:17 +00:00
|
|
|
const hours = Math.floor(EXPIRE_SECONDS / 60 / 60);
|
2018-02-11 22:02:40 +00:00
|
|
|
const el = html`<div>${raw(
|
|
|
|
translate('expireInfo', {
|
2017-11-30 21:41:09 +00:00
|
|
|
downloadCount: '<select></select>',
|
2017-12-14 02:22:17 +00:00
|
|
|
timespan: translate('timespanHours', { num: hours })
|
2018-02-11 22:02:40 +00:00
|
|
|
})
|
|
|
|
)}</div>`;
|
2017-11-30 21:41:09 +00:00
|
|
|
const select = el.querySelector('select');
|
2018-01-30 20:15:09 +00:00
|
|
|
const options = [1, 2, 3, 4, 5, 20].filter(i => i > (file.dtotal || 0));
|
2017-12-06 03:07:23 +00:00
|
|
|
const t = num => translate('downloadCount', { num });
|
2017-11-30 21:41:09 +00:00
|
|
|
const changed = value => emit('changeLimit', { file, value });
|
|
|
|
select.parentNode.replaceChild(
|
|
|
|
selectbox(file.dlimit || 1, options, t, changed),
|
|
|
|
select
|
|
|
|
);
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
module.exports = function(state, emit) {
|
|
|
|
const file = state.storage.getFileById(state.params.id);
|
|
|
|
if (!file) {
|
|
|
|
return notFound(state, emit);
|
|
|
|
}
|
2017-10-25 19:48:01 +00:00
|
|
|
|
2018-01-30 20:15:09 +00:00
|
|
|
const passwordSection = file.hasPassword
|
2018-02-13 19:32:59 +00:00
|
|
|
? changePasswordSection(state, emit)
|
|
|
|
: setPasswordSection(state, emit);
|
2017-08-24 21:54:02 +00:00
|
|
|
const div = html`
|
2018-02-13 19:32:59 +00:00
|
|
|
<div id="shareWrapper" class="effect--fadeIn">
|
2017-11-30 21:41:09 +00:00
|
|
|
<div class="title">${expireInfo(file, state.translate, emit)}</div>
|
2018-02-13 19:32:59 +00:00
|
|
|
<div class="sharePage">
|
|
|
|
<div class="sharePage__copyText">
|
2018-01-24 18:23:13 +00:00
|
|
|
${state.translate('copyUrlFormLabelWithName', { filename: file.name })}
|
|
|
|
</div>
|
2018-02-13 19:32:59 +00:00
|
|
|
<div class="copySection">
|
|
|
|
<input
|
|
|
|
id="fileUrl"
|
|
|
|
class="copySection__url"
|
|
|
|
type="url"
|
|
|
|
value="${file.url}"
|
|
|
|
readonly="true"/>
|
|
|
|
<button id="copyBtn"
|
|
|
|
class="inputBtn inputBtn--copy"
|
2017-08-31 16:43:36 +00:00
|
|
|
title="${state.translate('copyUrlFormButton')}"
|
|
|
|
onclick=${copyLink}>${state.translate('copyUrlFormButton')}</button>
|
2017-08-24 21:54:02 +00:00
|
|
|
</div>
|
2017-08-31 16:43:36 +00:00
|
|
|
${passwordSection}
|
2018-02-13 19:32:59 +00:00
|
|
|
<button
|
|
|
|
class="btn btn--delete"
|
2017-08-31 16:43:36 +00:00
|
|
|
title="${state.translate('deleteFileButton')}"
|
2017-12-23 03:20:19 +00:00
|
|
|
onclick=${showPopup}>${state.translate('deleteFileButton')}
|
2018-01-09 15:26:27 +00:00
|
|
|
</button>
|
2018-02-13 19:32:59 +00:00
|
|
|
<div class="sharePage__deletePopup">
|
|
|
|
${deletePopup(
|
|
|
|
state.translate('deletePopupText'),
|
|
|
|
state.translate('deletePopupYes'),
|
|
|
|
state.translate('deletePopupCancel'),
|
|
|
|
deleteFile
|
|
|
|
)}
|
2018-01-09 15:26:27 +00:00
|
|
|
</div>
|
2018-02-13 19:32:59 +00:00
|
|
|
<a class="link link--action"
|
2017-08-31 16:43:36 +00:00
|
|
|
href="/"
|
|
|
|
onclick=${sendNew}>${state.translate('sendAnotherFileLink')}</a>
|
2017-08-24 21:54:02 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
2017-12-23 03:20:19 +00:00
|
|
|
function showPopup() {
|
2018-02-13 19:32:59 +00:00
|
|
|
const popup = document.querySelector('.popup');
|
|
|
|
popup.classList.add('popup--show');
|
|
|
|
popup.focus();
|
2017-12-23 03:20:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
async function sendNew(e) {
|
|
|
|
e.preventDefault();
|
2018-02-13 19:32:59 +00:00
|
|
|
await fadeOut('#shareWrapper');
|
2017-08-24 21:54:02 +00:00
|
|
|
emit('pushState', '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function copyLink() {
|
|
|
|
if (allowedCopy()) {
|
|
|
|
emit('copy', { url: file.url, location: 'success-screen' });
|
2018-02-13 19:32:59 +00:00
|
|
|
const input = document.getElementById('fileUrl');
|
2017-08-29 18:25:41 +00:00
|
|
|
input.disabled = true;
|
2018-02-13 19:32:59 +00:00
|
|
|
const copyBtn = document.getElementById('copyBtn');
|
2017-08-24 21:54:02 +00:00
|
|
|
copyBtn.disabled = true;
|
2018-02-13 19:32:59 +00:00
|
|
|
copyBtn.classList.add('inputBtn--copied');
|
2017-08-24 21:54:02 +00:00
|
|
|
copyBtn.replaceChild(
|
2018-02-13 19:32:59 +00:00
|
|
|
html`<img src="${assets.get('check-16.svg')}" class="cursor--pointer">`,
|
2017-08-24 21:54:02 +00:00
|
|
|
copyBtn.firstChild
|
|
|
|
);
|
|
|
|
await delay(2000);
|
2017-08-29 18:25:41 +00:00
|
|
|
input.disabled = false;
|
2018-02-13 19:32:59 +00:00
|
|
|
copyBtn.disabled = false;
|
|
|
|
copyBtn.classList.remove('inputBtn--copied');
|
2017-08-24 21:54:02 +00:00
|
|
|
copyBtn.textContent = state.translate('copyUrlFormButton');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteFile() {
|
|
|
|
emit('delete', { file, location: 'success-screen' });
|
2018-02-13 19:32:59 +00:00
|
|
|
await fadeOut('#shareWrapper');
|
2017-08-24 21:54:02 +00:00
|
|
|
emit('pushState', '/');
|
|
|
|
}
|
|
|
|
return div;
|
|
|
|
};
|