datatrash/template/auth-hide.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

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