2017-12-14 03:22:17 +01:00
|
|
|
/* global EXPIRE_SECONDS */
|
2017-08-24 23:54:02 +02:00
|
|
|
const html = require('choo/html');
|
|
|
|
const assets = require('../../common/assets');
|
|
|
|
const notFound = require('./notFound');
|
2017-08-31 18:43:36 +02:00
|
|
|
const uploadPassword = require('./uploadPassword');
|
2017-11-30 22:41:09 +01:00
|
|
|
const selectbox = require('./selectbox');
|
2017-08-24 23:54:02 +02:00
|
|
|
const { allowedCopy, delay, fadeOut } = require('../utils');
|
|
|
|
|
2018-01-14 15:49:10 +01:00
|
|
|
function inputChanged() {
|
|
|
|
const resetInput = document.getElementById('unlock-reset-input');
|
|
|
|
const resetBtn = document.getElementById('unlock-reset-btn');
|
|
|
|
if (resetInput.value.length > 0) {
|
|
|
|
resetBtn.classList.remove('btn-hidden');
|
|
|
|
resetInput.classList.remove('input-no-btn');
|
|
|
|
} else {
|
|
|
|
resetBtn.classList.add('btn-hidden');
|
|
|
|
resetInput.classList.add('input-no-btn');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleResetInput(event) {
|
|
|
|
const form = event.target.parentElement.querySelector('form');
|
2018-01-20 01:53:57 +01:00
|
|
|
const input = document.getElementById('unlock-reset-input');
|
2018-01-14 15:49:10 +01:00
|
|
|
if (form.style.visibility === 'hidden' || form.style.visibility === '') {
|
|
|
|
form.style.visibility = 'visible';
|
2018-01-20 01:53:57 +01:00
|
|
|
input.focus();
|
2018-01-14 15:49:10 +01:00
|
|
|
} else {
|
|
|
|
form.style.visibility = 'hidden';
|
|
|
|
}
|
|
|
|
inputChanged();
|
|
|
|
}
|
|
|
|
|
2017-11-30 22:41:09 +01:00
|
|
|
function expireInfo(file, translate, emit) {
|
2017-12-14 03:22:17 +01:00
|
|
|
const hours = Math.floor(EXPIRE_SECONDS / 60 / 60);
|
2017-11-30 22:41:09 +01:00
|
|
|
const el = html([
|
|
|
|
`<div>${translate('expireInfo', {
|
|
|
|
downloadCount: '<select></select>',
|
2017-12-14 03:22:17 +01:00
|
|
|
timespan: translate('timespanHours', { num: hours })
|
2017-11-30 22:41:09 +01:00
|
|
|
})}</div>`
|
|
|
|
]);
|
|
|
|
const select = el.querySelector('select');
|
|
|
|
const options = [1, 2, 3, 4, 5, 20];
|
2017-12-06 04:07:23 +01:00
|
|
|
const t = num => translate('downloadCount', { num });
|
2017-11-30 22:41:09 +01:00
|
|
|
const changed = value => emit('changeLimit', { file, value });
|
|
|
|
select.parentNode.replaceChild(
|
|
|
|
selectbox(file.dlimit || 1, options, t, changed),
|
|
|
|
select
|
|
|
|
);
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
module.exports = function(state, emit) {
|
|
|
|
const file = state.storage.getFileById(state.params.id);
|
|
|
|
if (!file) {
|
|
|
|
return notFound(state, emit);
|
|
|
|
}
|
2017-10-25 21:48:01 +02:00
|
|
|
|
|
|
|
file.password = file.password || '';
|
|
|
|
|
2017-08-31 18:43:36 +02:00
|
|
|
const passwordSection = file.password
|
2018-01-20 01:53:57 +01:00
|
|
|
? passwordComplete(file.password)
|
2017-08-31 18:43:36 +02:00
|
|
|
: uploadPassword(state, emit);
|
2017-08-24 23:54:02 +02:00
|
|
|
const div = html`
|
|
|
|
<div id="share-link" class="fadeIn">
|
2017-11-30 22:41:09 +01:00
|
|
|
<div class="title">${expireInfo(file, state.translate, emit)}</div>
|
2017-08-24 23:54:02 +02:00
|
|
|
<div id="share-window">
|
2017-08-31 18:43:36 +02:00
|
|
|
<div id="copy-text">
|
|
|
|
${state.translate('copyUrlFormLabelWithName', {
|
|
|
|
filename: file.name
|
|
|
|
})}</div>
|
2017-08-24 23:54:02 +02:00
|
|
|
<div id="copy">
|
|
|
|
<input id="link" type="url" value="${file.url}" readonly="true"/>
|
2017-08-31 18:43:36 +02:00
|
|
|
<button id="copy-btn"
|
|
|
|
class="btn"
|
|
|
|
title="${state.translate('copyUrlFormButton')}"
|
|
|
|
onclick=${copyLink}>${state.translate('copyUrlFormButton')}</button>
|
2017-08-24 23:54:02 +02:00
|
|
|
</div>
|
2017-08-31 18:43:36 +02:00
|
|
|
${passwordSection}
|
|
|
|
<button id="delete-file"
|
|
|
|
class="btn"
|
|
|
|
title="${state.translate('deleteFileButton')}"
|
2017-12-23 04:20:19 +01:00
|
|
|
onclick=${showPopup}>${state.translate('deleteFileButton')}
|
2018-01-09 16:26:27 +01:00
|
|
|
</button>
|
|
|
|
<div id="deletePopup" class="popup">
|
|
|
|
<div class="popuptext" onblur=${cancel} tabindex="-1">
|
|
|
|
<div class="popup-message">${state.translate('deletePopupText')}
|
|
|
|
</div>
|
|
|
|
<div class="popup-action">
|
|
|
|
<span class="popup-no" onclick=${cancel}>${state.translate(
|
2017-12-23 04:20:19 +01:00
|
|
|
'deletePopupCancel'
|
2018-01-09 16:26:27 +01:00
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
<span class="popup-yes" onclick=${deleteFile}>${state.translate(
|
2017-12-23 04:20:19 +01:00
|
|
|
'deletePopupYes'
|
2018-01-09 16:26:27 +01:00
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-08-31 18:43:36 +02:00
|
|
|
<a class="send-new"
|
|
|
|
data-state="completed"
|
|
|
|
href="/"
|
|
|
|
onclick=${sendNew}>${state.translate('sendAnotherFileLink')}</a>
|
2017-08-24 23:54:02 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
2018-01-20 01:53:57 +01:00
|
|
|
function passwordComplete(password) {
|
|
|
|
const el = html`<div class="selectPassword">
|
|
|
|
<button
|
|
|
|
id="resetButton"
|
|
|
|
onclick=${toggleResetInput}
|
|
|
|
>${state.translate('changePasswordButton')}</button>
|
|
|
|
<form
|
|
|
|
id='reset-form'
|
|
|
|
class="setPassword hidden"
|
|
|
|
onsubmit=${resetPassword}
|
|
|
|
data-no-csrf>
|
|
|
|
<input id="unlock-reset-input"
|
|
|
|
class="unlock-input input-no-btn"
|
|
|
|
maxlength="32"
|
|
|
|
autocomplete="off"
|
|
|
|
type="password"
|
|
|
|
oninput=${inputChanged}
|
|
|
|
placeholder="${state.translate('unlockInputPlaceholder')}">
|
|
|
|
<input type="submit"
|
|
|
|
id="unlock-reset-btn"
|
|
|
|
class="btn btn-hidden"
|
|
|
|
value="${state.translate('changePasswordButton')}"/>
|
|
|
|
</form>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
const passwordSpan = html([
|
|
|
|
`<span>${state.translate('passwordResult', {
|
|
|
|
password:
|
|
|
|
'<pre class="passwordOriginal"></pre><pre class="passwordStar"></pre>'
|
|
|
|
})}</span>`
|
|
|
|
]);
|
|
|
|
passwordSpan.querySelector('.passwordOriginal').textContent = password;
|
|
|
|
passwordSpan.querySelector('.passwordStar').textContent = password.replace(
|
|
|
|
/./g,
|
|
|
|
'●'
|
|
|
|
);
|
|
|
|
el.insertBefore(passwordSpan, el.firstElementChild);
|
|
|
|
return el;
|
|
|
|
}
|
2018-01-14 15:49:10 +01:00
|
|
|
|
|
|
|
function resetPassword(event) {
|
|
|
|
event.preventDefault();
|
2018-01-20 01:53:57 +01:00
|
|
|
const existingPassword = file.password;
|
2018-01-14 15:49:10 +01:00
|
|
|
const password = document.querySelector('#unlock-reset-input').value;
|
|
|
|
if (password.length > 0) {
|
|
|
|
document.getElementById('copy').classList.remove('wait-password');
|
|
|
|
document.getElementById('copy-btn').disabled = false;
|
|
|
|
emit('password', { existingPassword, password, file });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-23 04:20:19 +01:00
|
|
|
function showPopup() {
|
|
|
|
const popupText = document.querySelector('.popuptext');
|
|
|
|
popupText.classList.add('show');
|
2018-01-09 20:20:36 +01:00
|
|
|
popupText.focus();
|
2017-12-23 04:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function cancel(e) {
|
|
|
|
e.stopPropagation();
|
2018-01-09 16:26:27 +01:00
|
|
|
const popupText = document.querySelector('.popuptext');
|
2017-12-23 04:20:19 +01:00
|
|
|
popupText.classList.remove('show');
|
|
|
|
}
|
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
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 20:25:41 +02:00
|
|
|
const input = document.getElementById('link');
|
|
|
|
input.disabled = true;
|
2017-08-24 23:54:02 +02:00
|
|
|
const copyBtn = document.getElementById('copy-btn');
|
|
|
|
copyBtn.disabled = true;
|
2017-10-23 15:51:33 +02:00
|
|
|
copyBtn.classList.add('success');
|
2017-08-24 23:54:02 +02:00
|
|
|
copyBtn.replaceChild(
|
|
|
|
html`<img src="${assets.get('check-16.svg')}" class="icon-check">`,
|
|
|
|
copyBtn.firstChild
|
|
|
|
);
|
|
|
|
await delay(2000);
|
2017-08-29 20:25:41 +02:00
|
|
|
input.disabled = false;
|
2017-10-24 19:00:27 +02:00
|
|
|
if (!copyBtn.parentNode.classList.contains('wait-password')) {
|
|
|
|
copyBtn.disabled = false;
|
|
|
|
}
|
2017-10-23 15:51:33 +02:00
|
|
|
copyBtn.classList.remove('success');
|
2017-08-24 23:54:02 +02:00
|
|
|
copyBtn.textContent = state.translate('copyUrlFormButton');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteFile() {
|
|
|
|
emit('delete', { file, location: 'success-screen' });
|
|
|
|
await fadeOut('share-link');
|
|
|
|
emit('pushState', '/');
|
|
|
|
}
|
|
|
|
return div;
|
|
|
|
};
|