39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
const fileUpload = document.getElementById('file-upload');
|
|
const textUpload = document.getElementById('text-upload');
|
|
const keepFor = document.getElementById('keep_for');
|
|
const passwordInput = document.getElementById('password-input');
|
|
|
|
const maxTime = Number('{no_auth_max_time}');
|
|
const largeFileMaxTime = Number('{no_auth_large_file_max_time}');
|
|
const largeFileSize = Number('{no_auth_large_file_size}');
|
|
|
|
let keep = Number(keepFor.value);
|
|
let size = fileUpload.files[0]
|
|
? fileUpload.files[0].size
|
|
: textUpload.value.length;
|
|
|
|
const updatePasswordInput = () => {
|
|
const requirePassword =
|
|
keep > maxTime || (size > largeFileSize && keep > largeFileMaxTime);
|
|
passwordInput.className = requirePassword ? '' : 'hidden';
|
|
};
|
|
|
|
updatePasswordInput();
|
|
|
|
fileUpload.addEventListener('change', () => {
|
|
size = fileUpload.files[0]
|
|
? fileUpload.files[0].size
|
|
: textUpload.value.length;
|
|
updatePasswordInput();
|
|
});
|
|
textUpload.addEventListener('input', () => {
|
|
if (!fileUpload.files[0]) {
|
|
size = textUpload.value.length;
|
|
updatePasswordInput();
|
|
}
|
|
});
|
|
keepFor.addEventListener('change', () => {
|
|
keep = Number(keepFor.value);
|
|
updatePasswordInput();
|
|
});
|