2019-02-28 22:28:18 +00:00
|
|
|
const html = require('choo/html');
|
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
|
|
|
const fileInfo = state.fileInfo;
|
|
|
|
const invalid = fileInfo.password === null;
|
|
|
|
|
|
|
|
const div = html`
|
|
|
|
<div
|
2019-09-09 17:34:55 +00:00
|
|
|
class="h-full w-full flex flex-col items-center justify-center bg-white py-8 max-w-md mx-auto dark:bg-grey-90"
|
2019-02-28 22:28:18 +00:00
|
|
|
>
|
2019-06-14 18:30:43 +00:00
|
|
|
<h1 class="text-3xl font-bold mb-4">
|
|
|
|
${state.translate('downloadTitle')}
|
|
|
|
</h1>
|
2019-09-09 17:34:55 +00:00
|
|
|
<p
|
|
|
|
class="w-full mb-4 text-center text-grey-80 dark:text-grey-40 leading-normal"
|
|
|
|
>
|
2019-03-04 22:13:18 +00:00
|
|
|
${state.translate('downloadDescription')}
|
2019-02-28 22:28:18 +00:00
|
|
|
</p>
|
|
|
|
<form
|
2022-07-26 16:52:29 +00:00
|
|
|
class="flex flex-row flex-nowrap w-full md:w-4/5"
|
2019-02-28 22:28:18 +00:00
|
|
|
onsubmit="${checkPassword}"
|
|
|
|
data-no-csrf
|
|
|
|
>
|
2020-07-28 22:12:31 +00:00
|
|
|
<input
|
|
|
|
id="autocomplete-decoy"
|
|
|
|
class="hidden"
|
|
|
|
type="password"
|
|
|
|
value="lol"
|
|
|
|
/>
|
2019-02-28 22:28:18 +00:00
|
|
|
<input
|
|
|
|
id="password-input"
|
|
|
|
class="w-full border-l border-t border-b rounded-l-lg rounded-r-none ${invalid
|
2019-09-09 17:34:55 +00:00
|
|
|
? 'border-red dark:border-red-40'
|
|
|
|
: 'border-grey'} leading-loose px-2 py-1 dark:bg-grey-80"
|
2023-02-14 12:36:19 +00:00
|
|
|
maxlength="4096"
|
2019-02-28 22:28:18 +00:00
|
|
|
autocomplete="off"
|
|
|
|
placeholder="${state.translate('unlockInputPlaceholder')}"
|
|
|
|
oninput="${inputChanged}"
|
|
|
|
type="password"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="submit"
|
|
|
|
id="password-btn"
|
|
|
|
class="btn rounded-r-lg rounded-l-none ${invalid
|
2019-09-09 17:34:55 +00:00
|
|
|
? 'bg-red hover:bg-red focus:bg-red dark:bg-red-40'
|
2019-02-28 22:28:18 +00:00
|
|
|
: ''}"
|
|
|
|
value="${state.translate('unlockButtonLabel')}"
|
|
|
|
title="${state.translate('unlockButtonLabel')}"
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<label
|
|
|
|
id="password-error"
|
2019-09-09 17:34:55 +00:00
|
|
|
class="${invalid ? '' : 'invisible'} text-red dark:text-red-40 my-4"
|
2019-02-28 22:28:18 +00:00
|
|
|
for="password-input"
|
|
|
|
>
|
|
|
|
${state.translate('passwordTryAgain')}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
if (!(div instanceof String)) {
|
|
|
|
setTimeout(() => document.getElementById('password-input').focus());
|
|
|
|
}
|
|
|
|
|
|
|
|
function inputChanged(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
const label = document.getElementById('password-error');
|
|
|
|
const input = document.getElementById('password-input');
|
|
|
|
const btn = document.getElementById('password-btn');
|
|
|
|
label.classList.add('invisible');
|
2020-07-31 15:49:24 +00:00
|
|
|
input.classList.remove('border-red', 'dark:border-red-40');
|
|
|
|
btn.classList.remove(
|
|
|
|
'bg-red',
|
|
|
|
'hover:bg-red',
|
|
|
|
'focus:bg-red',
|
|
|
|
'dark:bg-red-40'
|
|
|
|
);
|
2019-02-28 22:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkPassword(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
const el = document.getElementById('password-input');
|
|
|
|
const password = el.value;
|
|
|
|
if (password.length > 0) {
|
|
|
|
document.getElementById('password-btn').disabled = true;
|
2019-10-15 13:29:48 +00:00
|
|
|
// Strip any url parameters between fileId and secretKey
|
|
|
|
const fileInfoUrl = window.location.href.replace(/\?.+#/, '#');
|
|
|
|
state.fileInfo.url = fileInfoUrl;
|
2019-02-28 22:28:18 +00:00
|
|
|
state.fileInfo.password = password;
|
|
|
|
emit('getMetadata');
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return div;
|
|
|
|
};
|