WebPass / webpass /static /js /file_tools.js
ag235772's picture
Initial Release: WebPass V2 with Steganography, Crypto Vault, and Cloud Toggle
136c0f7
document.addEventListener("DOMContentLoaded", () => {
// ENCRYPT
const encryptForm = document.getElementById("encryptForm");
const encryptError = document.getElementById("encryptError");
encryptForm.addEventListener("submit", async e => {
e.preventDefault();
encryptError.classList.add("d-none");
const form = new FormData(encryptForm);
try {
const res = await fetch("/api/encrypt-file", {
method: "POST",
body: form,
credentials: "same-origin"
});
if (!res.ok) {
const err = await res.json();
throw new Error(err.error || res.statusText);
}
const blob = await res.blob();
const cd = res.headers.get("Content-Disposition");
const name = cd?.split("filename=")[1] || "encrypted.zip";
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = name;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
bootstrap.Modal.getInstance(
encryptForm.closest(".modal")
).hide();
}
catch (err) {
encryptError.textContent = err.message;
encryptError.classList.remove("d-none");
}
});
// DECRYPT
const decryptForm = document.getElementById("decryptForm");
const decryptError = document.getElementById("decryptError");
decryptForm.addEventListener("submit", async e => {
e.preventDefault();
decryptError.classList.add("d-none");
const form = new FormData(decryptForm);
try {
const res = await fetch("/api/decrypt-file", {
method: "POST",
body: form,
credentials: "same-origin"
});
if (!res.ok) {
const err = await res.json();
throw new Error(err.error || res.statusText);
}
const blob = await res.blob();
const cd = res.headers.get("Content-Disposition");
const name = cd?.split("filename=")[1] || "decrypted.bin";
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = name;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
bootstrap.Modal.getInstance(
decryptForm.closest(".modal")
).hide();
}
catch (err) {
decryptError.textContent = err.message;
decryptError.classList.remove("d-none");
}
});
});