2017-08-24 21:54:02 +00:00
|
|
|
const html = require('choo/html');
|
|
|
|
const assets = require('../../common/assets');
|
|
|
|
const notFound = require('./notFound');
|
2017-08-31 16:43:36 +00:00
|
|
|
const uploadPassword = require('./uploadPassword');
|
2017-11-30 21:41:09 +00:00
|
|
|
const selectbox = require('./selectbox');
|
2017-08-24 21:54:02 +00:00
|
|
|
const { allowedCopy, delay, fadeOut } = require('../utils');
|
|
|
|
|
2017-11-02 21:27:54 +00:00
|
|
|
function passwordComplete(state, password) {
|
|
|
|
const el = html([
|
|
|
|
`<div class="selectPassword">${state.translate('passwordResult', {
|
|
|
|
password: '<pre></pre>'
|
|
|
|
})}</div>`
|
|
|
|
]);
|
2017-12-21 09:47:31 +00:00
|
|
|
const displayPassword = [];
|
|
|
|
for (let i = 0; i < password.length; i++) {
|
|
|
|
displayPassword[i] = '●';
|
|
|
|
}
|
|
|
|
|
|
|
|
const passwordOriginal = document.createElement('div');
|
|
|
|
passwordOriginal.className = 'passwordOriginal';
|
|
|
|
passwordOriginal.innerText = password;
|
|
|
|
|
|
|
|
const passwordStar = document.createElement('div');
|
|
|
|
passwordStar.className = 'passwordStar';
|
|
|
|
passwordStar.innerText = displayPassword
|
|
|
|
.toString()
|
|
|
|
.split(',')
|
|
|
|
.join('');
|
|
|
|
el.lastElementChild.appendChild(passwordOriginal);
|
|
|
|
el.lastElementChild.appendChild(passwordStar);
|
2017-11-02 21:27:54 +00:00
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
2017-11-30 21:41:09 +00:00
|
|
|
function expireInfo(file, translate, emit) {
|
|
|
|
const el = html([
|
|
|
|
`<div>${translate('expireInfo', {
|
|
|
|
downloadCount: '<select></select>',
|
2017-12-06 03:07:23 +00:00
|
|
|
timespan: translate('timespanHours', { num: 24 })
|
2017-11-30 21:41:09 +00:00
|
|
|
})}</div>`
|
|
|
|
]);
|
|
|
|
const select = el.querySelector('select');
|
|
|
|
const options = [1, 2, 3, 4, 5, 20];
|
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
|
|
|
|
|
|
|
file.password = file.password || '';
|
|
|
|
|
2017-08-31 16:43:36 +00:00
|
|
|
const passwordSection = file.password
|
2017-11-02 21:27:54 +00:00
|
|
|
? passwordComplete(state, file.password)
|
2017-08-31 16:43:36 +00:00
|
|
|
: uploadPassword(state, emit);
|
2017-08-24 21:54:02 +00:00
|
|
|
const div = html`
|
|
|
|
<div id="share-link" class="fadeIn">
|
2017-11-30 21:41:09 +00:00
|
|
|
<div class="title">${expireInfo(file, state.translate, emit)}</div>
|
2017-08-24 21:54:02 +00:00
|
|
|
<div id="share-window">
|
2017-08-31 16:43:36 +00:00
|
|
|
<div id="copy-text">
|
|
|
|
${state.translate('copyUrlFormLabelWithName', {
|
|
|
|
filename: file.name
|
|
|
|
})}</div>
|
2017-08-24 21:54:02 +00:00
|
|
|
<div id="copy">
|
|
|
|
<input id="link" type="url" value="${file.url}" readonly="true"/>
|
2017-08-31 16:43:36 +00:00
|
|
|
<button id="copy-btn"
|
|
|
|
class="btn"
|
|
|
|
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}
|
|
|
|
<button id="delete-file"
|
|
|
|
class="btn"
|
|
|
|
title="${state.translate('deleteFileButton')}"
|
|
|
|
onclick=${deleteFile}>${state.translate('deleteFileButton')}</button>
|
|
|
|
<a class="send-new"
|
|
|
|
data-state="completed"
|
|
|
|
href="/"
|
|
|
|
onclick=${sendNew}>${state.translate('sendAnotherFileLink')}</a>
|
2017-08-24 21:54:02 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
async function sendNew(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
await fadeOut('share-link');
|
|
|
|
emit('pushState', '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function copyLink() {
|
|
|
|
if (allowedCopy()) {
|
|
|
|
emit('copy', { url: file.url, location: 'success-screen' });
|
2017-08-29 18:25:41 +00:00
|
|
|
const input = document.getElementById('link');
|
|
|
|
input.disabled = true;
|
2017-08-24 21:54:02 +00:00
|
|
|
const copyBtn = document.getElementById('copy-btn');
|
|
|
|
copyBtn.disabled = true;
|
2017-10-23 13:51:33 +00:00
|
|
|
copyBtn.classList.add('success');
|
2017-08-24 21:54:02 +00:00
|
|
|
copyBtn.replaceChild(
|
|
|
|
html`<img src="${assets.get('check-16.svg')}" class="icon-check">`,
|
|
|
|
copyBtn.firstChild
|
|
|
|
);
|
|
|
|
await delay(2000);
|
2017-08-29 18:25:41 +00:00
|
|
|
input.disabled = false;
|
2017-10-24 17:00:27 +00:00
|
|
|
if (!copyBtn.parentNode.classList.contains('wait-password')) {
|
|
|
|
copyBtn.disabled = false;
|
|
|
|
}
|
2017-10-23 13:51:33 +00:00
|
|
|
copyBtn.classList.remove('success');
|
2017-08-24 21:54:02 +00:00
|
|
|
copyBtn.textContent = state.translate('copyUrlFormButton');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteFile() {
|
|
|
|
emit('delete', { file, location: 'success-screen' });
|
|
|
|
await fadeOut('share-link');
|
|
|
|
emit('pushState', '/');
|
|
|
|
}
|
|
|
|
return div;
|
|
|
|
};
|