2026-04-25 18:46:16 +03:00
|
|
|
const fileInput = document.querySelector("#file-upload");
|
|
|
|
|
const fileCount = document.querySelector("#upload-file-count");
|
|
|
|
|
const fileList = document.querySelector(".upload-file-list");
|
|
|
|
|
const dropzone = document.querySelector(".upload-dropzone");
|
|
|
|
|
const uploadForm = document.querySelector(".upload-form");
|
|
|
|
|
const uploadStatus = document.querySelector(".upload-statusbar span:first-child");
|
2026-04-25 18:57:08 +03:00
|
|
|
const boxStatus = document.querySelector(".upload-statusbar span:last-child");
|
2026-04-27 17:26:57 +03:00
|
|
|
const uploadResult = document.querySelector(".upload-result");
|
2026-04-27 17:20:57 +03:00
|
|
|
const boxLink = document.querySelector("#upload-box-link");
|
|
|
|
|
const shareButton = document.querySelector("#upload-share-button");
|
2026-04-27 17:26:57 +03:00
|
|
|
const overallProgressBar = document.querySelector(".upload-overall-bar");
|
|
|
|
|
const overallProgressPercent = document.querySelector(".upload-overall-percent");
|
2026-04-27 18:18:53 +03:00
|
|
|
const retentionSelect = document.querySelector("#upload-retention");
|
|
|
|
|
const passwordEnabled = document.querySelector("#upload-password-enabled");
|
|
|
|
|
const passwordInput = document.querySelector("#upload-password");
|
|
|
|
|
const zipEnabled = document.querySelector("#upload-zip-enabled");
|
2026-04-28 19:41:23 +03:00
|
|
|
const oneTimeRetentionKey = "one-time";
|
2026-04-25 18:57:08 +03:00
|
|
|
|
|
|
|
|
let selectedFiles = [];
|
|
|
|
|
let statusTimer = null;
|
2026-04-27 17:20:57 +03:00
|
|
|
let shareURL = "";
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-28 18:44:16 +03:00
|
|
|
function revokePreviewURLs() {
|
|
|
|
|
selectedFiles.forEach((selectedFile) => {
|
|
|
|
|
if (selectedFile.previewURL) {
|
|
|
|
|
URL.revokeObjectURL(selectedFile.previewURL);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 18:46:16 +03:00
|
|
|
function formatBytes(bytes) {
|
|
|
|
|
const units = ["B", "KB", "MB", "GB"];
|
|
|
|
|
let size = bytes;
|
|
|
|
|
let unitIndex = 0;
|
|
|
|
|
|
|
|
|
|
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
|
|
|
size /= 1024;
|
|
|
|
|
unitIndex += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unitIndex === 0) {
|
|
|
|
|
return `${size} ${units[unitIndex]}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return `${size.toFixed(1)} ${units[unitIndex]}`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 18:37:05 +03:00
|
|
|
function iconForFile(file) {
|
|
|
|
|
const filename = file.name || "";
|
|
|
|
|
const mimeType = file.type || "";
|
|
|
|
|
const extension = filename.includes(".") ? filename.slice(filename.lastIndexOf(".")).toLowerCase() : "";
|
|
|
|
|
|
|
|
|
|
if (extension === ".exe") {
|
|
|
|
|
return "/static/img/icons/Program Files Icons - PNG/MSONSEXT.DLL_14_6-0.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mimeType.startsWith("image/")) {
|
|
|
|
|
return "/static/img/sprites/bitmap.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mimeType.startsWith("video/") || mimeType.startsWith("audio/")) {
|
|
|
|
|
return "/static/img/icons/netshow_notransm-1.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mimeType.startsWith("text/") || extension === ".md") {
|
|
|
|
|
return "/static/img/sprites/notepad_file-1.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
mimeType.includes("zip") ||
|
|
|
|
|
mimeType.includes("compressed") ||
|
|
|
|
|
[".rar", ".7z", ".tar", ".gz"].includes(extension)
|
|
|
|
|
) {
|
|
|
|
|
return "/static/img/icons/Windows Icons - PNG/zipfldr.dll_14_101-0.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([".ttf", ".otf", ".woff", ".woff2"].includes(extension)) {
|
|
|
|
|
return "/static/img/sprites/font.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (extension === ".pdf") {
|
|
|
|
|
return "/static/img/sprites/journal.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([".html", ".css", ".js"].includes(extension)) {
|
|
|
|
|
return "/static/img/sprites/frame_web-0.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "/static/img/icons/Windows Icons - PNG/ole2.dll_14_DEFICON.png";
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 18:46:16 +03:00
|
|
|
function updateStatus(message) {
|
|
|
|
|
if (uploadStatus) {
|
|
|
|
|
uploadStatus.textContent = message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
function stopStatusAnimation() {
|
|
|
|
|
if (statusTimer) {
|
|
|
|
|
clearInterval(statusTimer);
|
|
|
|
|
statusTimer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function animateUploadStatus(getPrefix) {
|
|
|
|
|
let dotCount = 0;
|
|
|
|
|
stopStatusAnimation();
|
|
|
|
|
|
|
|
|
|
statusTimer = setInterval(() => {
|
|
|
|
|
dotCount = (dotCount % 3) + 1;
|
|
|
|
|
updateStatus(`${getPrefix()} Uploading${".".repeat(dotCount)}`);
|
|
|
|
|
}, 350);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setBoxStatus(message) {
|
|
|
|
|
if (boxStatus) {
|
|
|
|
|
boxStatus.textContent = message;
|
|
|
|
|
boxStatus.title = message;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-28 19:41:23 +03:00
|
|
|
function isOneTimeDownloadSelected() {
|
|
|
|
|
return retentionSelect && retentionSelect.value === oneTimeRetentionKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateZipOptionForRetention() {
|
|
|
|
|
if (!zipEnabled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isOneTimeDownloadSelected()) {
|
|
|
|
|
zipEnabled.checked = true;
|
|
|
|
|
zipEnabled.disabled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zipEnabled.disabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 17:20:57 +03:00
|
|
|
function setBoxLink(path) {
|
|
|
|
|
shareURL = path ? new URL(path, window.location.origin).toString() : "";
|
|
|
|
|
|
2026-04-27 17:26:57 +03:00
|
|
|
if (uploadResult) {
|
|
|
|
|
uploadResult.classList.toggle("is-hidden", !shareURL);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 17:20:57 +03:00
|
|
|
if (boxLink) {
|
|
|
|
|
boxLink.href = shareURL || "#";
|
|
|
|
|
boxLink.textContent = shareURL || "Waiting for upload";
|
|
|
|
|
boxLink.title = shareURL;
|
|
|
|
|
boxLink.classList.toggle("is-empty", !shareURL);
|
|
|
|
|
boxLink.setAttribute("aria-disabled", shareURL ? "false" : "true");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shareButton) {
|
|
|
|
|
shareButton.disabled = !shareURL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 17:26:57 +03:00
|
|
|
function setOverallProgress(percent) {
|
|
|
|
|
const clampedPercent = Math.max(0, Math.min(100, percent));
|
|
|
|
|
const displayPercent = `${Math.round(clampedPercent)}%`;
|
|
|
|
|
|
|
|
|
|
if (overallProgressBar) {
|
|
|
|
|
overallProgressBar.style.width = displayPercent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (overallProgressPercent) {
|
|
|
|
|
overallProgressPercent.textContent = displayPercent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateOverallProgress() {
|
|
|
|
|
const totalBytes = selectedFiles.reduce((total, selectedFile) => total + selectedFile.file.size, 0);
|
|
|
|
|
const loadedBytes = selectedFiles.reduce((total, selectedFile) => total + selectedFile.loaded, 0);
|
2026-04-27 17:33:52 +03:00
|
|
|
const uploadedCount = selectedFiles.filter((selectedFile) => selectedFile.uploaded).length;
|
|
|
|
|
const percent = totalBytes > 0 ? (loadedBytes / totalBytes) * 100 : 0;
|
|
|
|
|
setOverallProgress(percent >= 100 && uploadedCount < selectedFiles.length ? 99 : percent);
|
2026-04-27 17:26:57 +03:00
|
|
|
}
|
|
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
function updateFileCount() {
|
2026-04-25 18:46:16 +03:00
|
|
|
if (fileCount) {
|
|
|
|
|
fileCount.textContent = `${selectedFiles.length} ${selectedFiles.length === 1 ? "file" : "files"}`;
|
|
|
|
|
}
|
2026-04-25 18:57:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setRowProgress(row, percent) {
|
|
|
|
|
const progressBar = row.querySelector(".upload-progress-bar");
|
|
|
|
|
if (progressBar) {
|
|
|
|
|
progressBar.style.width = `${Math.max(0, Math.min(100, percent))}%`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createFileRow(selectedFile) {
|
|
|
|
|
const row = document.createElement("div");
|
|
|
|
|
row.className = "upload-file-row";
|
2026-04-28 18:44:16 +03:00
|
|
|
row.classList.toggle("has-thumbnail", Boolean(selectedFile.previewURL));
|
2026-04-25 18:57:08 +03:00
|
|
|
|
2026-04-27 18:37:05 +03:00
|
|
|
const icon = document.createElement("img");
|
2026-04-25 18:57:08 +03:00
|
|
|
icon.className = "upload-file-icon";
|
2026-04-28 18:44:16 +03:00
|
|
|
icon.src = selectedFile.previewURL || iconForFile(selectedFile.file);
|
2026-04-27 18:37:05 +03:00
|
|
|
icon.alt = "";
|
2026-04-25 18:57:08 +03:00
|
|
|
icon.setAttribute("aria-hidden", "true");
|
|
|
|
|
|
|
|
|
|
const name = document.createElement("span");
|
|
|
|
|
name.className = "upload-file-name";
|
|
|
|
|
name.textContent = selectedFile.file.name;
|
|
|
|
|
name.title = selectedFile.file.name;
|
|
|
|
|
|
|
|
|
|
const size = document.createElement("span");
|
|
|
|
|
size.className = "upload-file-size";
|
|
|
|
|
size.textContent = formatBytes(selectedFile.file.size);
|
|
|
|
|
|
|
|
|
|
const progress = document.createElement("span");
|
|
|
|
|
progress.className = "upload-progress";
|
|
|
|
|
progress.setAttribute("aria-hidden", "true");
|
|
|
|
|
|
|
|
|
|
const progressBar = document.createElement("span");
|
|
|
|
|
progressBar.className = "upload-progress-bar";
|
|
|
|
|
progress.append(progressBar);
|
|
|
|
|
|
|
|
|
|
row.append(icon, name, size, progress);
|
|
|
|
|
selectedFile.row = row;
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateSelectedFiles(files) {
|
2026-04-28 18:44:16 +03:00
|
|
|
revokePreviewURLs();
|
2026-04-25 18:57:08 +03:00
|
|
|
selectedFiles = Array.from(files || []).map((file) => ({
|
|
|
|
|
file,
|
2026-04-28 18:44:16 +03:00
|
|
|
previewURL: file.type.startsWith("image/") ? URL.createObjectURL(file) : "",
|
2026-04-27 17:26:57 +03:00
|
|
|
loaded: 0,
|
2026-04-25 18:57:08 +03:00
|
|
|
row: null,
|
|
|
|
|
uploaded: false,
|
|
|
|
|
failed: false,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
updateFileCount();
|
2026-04-25 18:46:16 +03:00
|
|
|
|
|
|
|
|
if (!fileList) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileList.replaceChildren();
|
|
|
|
|
|
|
|
|
|
if (!selectedFiles.length) {
|
|
|
|
|
const emptyState = document.createElement("p");
|
|
|
|
|
emptyState.className = "upload-empty-state";
|
|
|
|
|
emptyState.textContent = "No files selected";
|
|
|
|
|
fileList.append(emptyState);
|
|
|
|
|
updateStatus("Ready");
|
2026-04-25 18:57:08 +03:00
|
|
|
setBoxStatus("WarpBox");
|
2026-04-27 17:20:57 +03:00
|
|
|
setBoxLink("");
|
2026-04-27 17:26:57 +03:00
|
|
|
setOverallProgress(0);
|
2026-04-25 18:46:16 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fragment = document.createDocumentFragment();
|
2026-04-25 18:57:08 +03:00
|
|
|
selectedFiles.forEach((selectedFile) => {
|
|
|
|
|
fragment.append(createFileRow(selectedFile));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fileList.append(fragment);
|
|
|
|
|
updateStatus("Files selected");
|
|
|
|
|
setBoxStatus("WarpBox");
|
2026-04-27 17:20:57 +03:00
|
|
|
setBoxLink("");
|
2026-04-27 17:26:57 +03:00
|
|
|
setOverallProgress(0);
|
2026-04-25 18:57:08 +03:00
|
|
|
}
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
async function createBox() {
|
2026-04-27 17:33:52 +03:00
|
|
|
const response = await fetch("/box", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
2026-04-27 18:18:53 +03:00
|
|
|
retention_key: retentionSelect ? retentionSelect.value : "10s",
|
|
|
|
|
password: passwordEnabled && passwordEnabled.checked && passwordInput ? passwordInput.value : "",
|
2026-04-28 19:41:23 +03:00
|
|
|
allow_zip: isOneTimeDownloadSelected() || !zipEnabled || zipEnabled.checked,
|
2026-04-27 17:33:52 +03:00
|
|
|
files: selectedFiles.map((selectedFile) => ({
|
|
|
|
|
name: selectedFile.file.name,
|
|
|
|
|
size: selectedFile.file.size,
|
|
|
|
|
})),
|
|
|
|
|
}),
|
|
|
|
|
});
|
2026-04-25 18:57:08 +03:00
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error("Could not create upload box");
|
|
|
|
|
}
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
return response.json();
|
|
|
|
|
}
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-27 17:33:52 +03:00
|
|
|
async function markFileStatus(selectedFile, status) {
|
|
|
|
|
if (!selectedFile.boxFile) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await fetch(`/box/${selectedFile.boxID}/files/${selectedFile.boxFile.id}/status`, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ status }),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
function uploadFile(boxID, selectedFile, onComplete) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("file", selectedFile.file);
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-27 17:33:52 +03:00
|
|
|
xhr.open("POST", selectedFile.boxFile.upload_path);
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
xhr.upload.addEventListener("loadstart", () => {
|
2026-04-27 17:26:57 +03:00
|
|
|
selectedFile.loaded = 0;
|
2026-04-27 17:33:52 +03:00
|
|
|
selectedFile.row.classList.add("is-uploading");
|
|
|
|
|
selectedFile.row.title = "Loading";
|
2026-04-27 17:26:57 +03:00
|
|
|
updateOverallProgress();
|
2026-04-25 18:57:08 +03:00
|
|
|
setRowProgress(selectedFile.row, 2);
|
|
|
|
|
});
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
xhr.upload.addEventListener("progress", (event) => {
|
|
|
|
|
if (!event.lengthComputable) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 17:26:57 +03:00
|
|
|
selectedFile.loaded = Math.min(event.loaded, selectedFile.file.size);
|
|
|
|
|
updateOverallProgress();
|
2026-04-27 17:33:52 +03:00
|
|
|
const percent = (event.loaded / event.total) * 100;
|
|
|
|
|
if (percent >= 100) {
|
|
|
|
|
selectedFile.row.classList.add("is-processing");
|
|
|
|
|
selectedFile.row.title = "Loading";
|
|
|
|
|
setRowProgress(selectedFile.row, 99);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setRowProgress(selectedFile.row, percent);
|
2026-04-25 18:57:08 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
xhr.addEventListener("load", () => {
|
|
|
|
|
if (xhr.status < 200 || xhr.status >= 300) {
|
|
|
|
|
selectedFile.failed = true;
|
2026-04-27 17:33:52 +03:00
|
|
|
selectedFile.row.classList.remove("is-uploading", "is-processing");
|
2026-04-25 18:57:08 +03:00
|
|
|
selectedFile.row.classList.add("is-failed");
|
2026-04-27 17:33:52 +03:00
|
|
|
selectedFile.row.title = "Failed to upload";
|
|
|
|
|
markFileStatus(selectedFile, "failed");
|
2026-04-25 18:57:08 +03:00
|
|
|
reject(new Error("Upload failed"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selectedFile.uploaded = true;
|
2026-04-27 17:26:57 +03:00
|
|
|
selectedFile.loaded = selectedFile.file.size;
|
2026-04-27 17:33:52 +03:00
|
|
|
selectedFile.row.classList.remove("is-uploading", "is-processing");
|
2026-04-25 18:57:08 +03:00
|
|
|
selectedFile.row.classList.add("is-uploaded");
|
2026-04-27 17:33:52 +03:00
|
|
|
selectedFile.row.title = "Uploaded";
|
2026-04-27 17:26:57 +03:00
|
|
|
updateOverallProgress();
|
2026-04-25 18:57:08 +03:00
|
|
|
setRowProgress(selectedFile.row, 100);
|
|
|
|
|
onComplete();
|
|
|
|
|
resolve();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
xhr.addEventListener("error", () => {
|
|
|
|
|
selectedFile.failed = true;
|
2026-04-27 17:33:52 +03:00
|
|
|
selectedFile.row.classList.remove("is-uploading", "is-processing");
|
2026-04-25 18:57:08 +03:00
|
|
|
selectedFile.row.classList.add("is-failed");
|
2026-04-27 17:33:52 +03:00
|
|
|
selectedFile.row.title = "Failed to upload";
|
|
|
|
|
markFileStatus(selectedFile, "failed");
|
2026-04-25 18:57:08 +03:00
|
|
|
reject(new Error("Upload failed"));
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-27 17:33:52 +03:00
|
|
|
xhr.addEventListener("abort", () => {
|
|
|
|
|
selectedFile.failed = true;
|
|
|
|
|
selectedFile.row.classList.remove("is-uploading", "is-processing");
|
|
|
|
|
selectedFile.row.classList.add("is-failed");
|
|
|
|
|
selectedFile.row.title = "Failed to upload";
|
|
|
|
|
markFileStatus(selectedFile, "failed");
|
|
|
|
|
reject(new Error("Upload cancelled"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
markFileStatus(selectedFile, "uploading");
|
2026-04-25 18:57:08 +03:00
|
|
|
xhr.send(formData);
|
|
|
|
|
});
|
2026-04-25 18:46:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fileInput) {
|
|
|
|
|
fileInput.addEventListener("change", () => {
|
2026-04-25 18:57:08 +03:00
|
|
|
stopStatusAnimation();
|
2026-04-25 18:46:16 +03:00
|
|
|
updateSelectedFiles(fileInput.files);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 18:18:53 +03:00
|
|
|
if (passwordEnabled && passwordInput) {
|
|
|
|
|
passwordEnabled.addEventListener("change", () => {
|
|
|
|
|
passwordInput.disabled = !passwordEnabled.checked;
|
|
|
|
|
if (!passwordEnabled.checked) {
|
|
|
|
|
passwordInput.value = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
passwordInput.focus();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 19:41:23 +03:00
|
|
|
if (retentionSelect) {
|
|
|
|
|
updateZipOptionForRetention();
|
|
|
|
|
retentionSelect.addEventListener("change", updateZipOptionForRetention);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 18:46:16 +03:00
|
|
|
if (fileInput && dropzone) {
|
|
|
|
|
dropzone.addEventListener("dragover", (event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
dropzone.classList.add("is-dragging");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dropzone.addEventListener("dragleave", () => {
|
|
|
|
|
dropzone.classList.remove("is-dragging");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dropzone.addEventListener("drop", (event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
dropzone.classList.remove("is-dragging");
|
|
|
|
|
|
|
|
|
|
if (!event.dataTransfer.files.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileInput.files = event.dataTransfer.files;
|
2026-04-25 18:57:08 +03:00
|
|
|
stopStatusAnimation();
|
2026-04-25 18:46:16 +03:00
|
|
|
updateSelectedFiles(fileInput.files);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
if (uploadForm) {
|
2026-04-25 18:46:16 +03:00
|
|
|
uploadForm.addEventListener("submit", async (event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
if (!selectedFiles.length) {
|
2026-04-25 18:46:16 +03:00
|
|
|
updateStatus("Choose files first");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 18:18:53 +03:00
|
|
|
if (passwordEnabled && passwordEnabled.checked && passwordInput && !passwordInput.value.trim()) {
|
|
|
|
|
updateStatus("Enter password");
|
|
|
|
|
passwordInput.focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
let completedCount = 0;
|
|
|
|
|
const totalCount = selectedFiles.length;
|
|
|
|
|
const statusPrefix = () => `${completedCount}/${totalCount}`;
|
|
|
|
|
|
|
|
|
|
selectedFiles.forEach((selectedFile) => {
|
|
|
|
|
selectedFile.uploaded = false;
|
|
|
|
|
selectedFile.failed = false;
|
2026-04-27 17:26:57 +03:00
|
|
|
selectedFile.loaded = 0;
|
2026-04-27 17:33:52 +03:00
|
|
|
selectedFile.row.classList.remove("is-uploaded", "is-failed", "is-uploading", "is-processing");
|
|
|
|
|
selectedFile.row.title = "";
|
2026-04-25 18:57:08 +03:00
|
|
|
setRowProgress(selectedFile.row, 0);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-27 17:26:57 +03:00
|
|
|
setBoxLink("");
|
|
|
|
|
setOverallProgress(0);
|
2026-04-25 18:57:08 +03:00
|
|
|
updateStatus(`${statusPrefix()} Uploading.`);
|
|
|
|
|
animateUploadStatus(statusPrefix);
|
2026-04-25 18:46:16 +03:00
|
|
|
|
|
|
|
|
try {
|
2026-04-25 18:57:08 +03:00
|
|
|
const box = await createBox();
|
|
|
|
|
setBoxStatus(box.box_url);
|
2026-04-27 17:33:52 +03:00
|
|
|
setBoxLink(box.box_url);
|
|
|
|
|
|
|
|
|
|
selectedFiles.forEach((selectedFile, index) => {
|
|
|
|
|
selectedFile.boxID = box.box_id;
|
|
|
|
|
selectedFile.boxFile = box.files[index];
|
2026-04-27 18:37:05 +03:00
|
|
|
const icon = selectedFile.row.querySelector(".upload-file-icon");
|
2026-04-28 18:44:16 +03:00
|
|
|
if (icon && selectedFile.boxFile.thumbnail_path) {
|
|
|
|
|
selectedFile.row.classList.add("has-thumbnail");
|
|
|
|
|
icon.src = selectedFile.boxFile.thumbnail_path;
|
|
|
|
|
} else if (icon && selectedFile.boxFile.icon_path && !selectedFile.previewURL) {
|
2026-04-27 18:37:05 +03:00
|
|
|
icon.src = selectedFile.boxFile.icon_path;
|
|
|
|
|
}
|
2026-04-27 17:33:52 +03:00
|
|
|
});
|
2026-04-25 18:57:08 +03:00
|
|
|
|
|
|
|
|
await Promise.allSettled(selectedFiles.map((selectedFile) => {
|
|
|
|
|
return uploadFile(box.box_id, selectedFile, () => {
|
|
|
|
|
completedCount += 1;
|
|
|
|
|
});
|
|
|
|
|
}));
|
2026-04-25 18:46:16 +03:00
|
|
|
|
2026-04-25 18:57:08 +03:00
|
|
|
stopStatusAnimation();
|
|
|
|
|
const failedCount = selectedFiles.filter((selectedFile) => selectedFile.failed).length;
|
|
|
|
|
if (failedCount > 0) {
|
|
|
|
|
updateStatus(`${completedCount}/${totalCount} Uploaded, ${failedCount} failed`);
|
|
|
|
|
return;
|
2026-04-25 18:46:16 +03:00
|
|
|
}
|
|
|
|
|
|
2026-04-27 17:26:57 +03:00
|
|
|
setOverallProgress(100);
|
2026-04-25 18:57:08 +03:00
|
|
|
updateStatus(`${completedCount}/${totalCount} Uploaded`);
|
2026-04-25 18:46:16 +03:00
|
|
|
} catch (error) {
|
2026-04-25 18:57:08 +03:00
|
|
|
stopStatusAnimation();
|
2026-04-27 17:26:57 +03:00
|
|
|
setBoxLink("");
|
2026-04-25 18:46:16 +03:00
|
|
|
updateStatus("Upload failed");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-04-27 17:20:57 +03:00
|
|
|
|
|
|
|
|
if (shareButton) {
|
|
|
|
|
shareButton.addEventListener("click", async () => {
|
|
|
|
|
if (!shareURL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (navigator.share) {
|
|
|
|
|
await navigator.share({
|
|
|
|
|
title: "WarpBox download",
|
|
|
|
|
text: "Download these files from WarpBox",
|
|
|
|
|
url: shareURL,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await navigator.clipboard.writeText(shareURL);
|
|
|
|
|
updateStatus("Link copied");
|
|
|
|
|
} catch (error) {
|
|
|
|
|
updateStatus("Share cancelled");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-04-28 18:44:16 +03:00
|
|
|
|
|
|
|
|
window.addEventListener("beforeunload", revokePreviewURLs);
|