datatrash/template/auth-hide.js

37 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}");
const updatePasswordInput = () => {
const requirePassword = keep > maxTime || (size > largeFileSize && keep > largeFileMaxTime);
passwordInput.className = requirePassword ? "" : "hidden";
};
let keep = Number(keepFor.value);
let size = fileUpload.files[0]
? fileUpload.files[0].size
: textUpload.value.length;
updatePasswordInput();
fileUpload.addEventListener("change", (e) => {
size = fileUpload.files[0]
? fileUpload.files[0].size
: textUpload.value.length;
updatePasswordInput();
});
textUpload.addEventListener("input", (e) => {
if (!fileUpload.files[0]) {
size = textUpload.value.length;
updatePasswordInput();
}
});
keepFor.addEventListener("change", (e) => {
keep = Number(keepFor.value);
updatePasswordInput();
});