Fix issue when uploading multiple files without zipping them

This commit is contained in:
Booteille 2025-04-16 16:48:13 +02:00
parent 6f26e0a1af
commit 15f75a06f4
No known key found for this signature in database
GPG Key ID: 0AB6C6CA01272646
1 changed files with 24 additions and 17 deletions

View File

@ -159,12 +159,16 @@ document.addEventListener("DOMContentLoaded", () => {
const serverUrl = new URL(ws_url.replace("/upload", "")); const serverUrl = new URL(ws_url.replace("/upload", ""));
serverUrl.protocol = serverUrl.protocol === "ws:" ? "http:" : "https:"; serverUrl.protocol = serverUrl.protocol === "ws:" ? "http:" : "https:";
const cardId = isSecureContext ? crypto.randomUUID() : uuidv4();
let uploadingFileCard = initCard("uploading", cardId);
document.getElementById("lufi-description").classList.add("is-hidden"); document.getElementById("lufi-description").classList.add("is-hidden");
const generateCardId = () =>
isSecureContext ? crypto.randomUUID() : uuidv4();
const zippedCardId = isZipped ? generateCardId() : null;
const zippedUploadingFileCard = isZipped
? initCard("uploading", zippedCardId)
: null;
const runUpload = (job = null) => { const runUpload = (job = null) => {
if (!job || job.status === JobStatus.COMPLETE) { if (!job || job.status === JobStatus.COMPLETE) {
return lufi return lufi
@ -181,8 +185,10 @@ document.addEventListener("DOMContentLoaded", () => {
.andThen((jobs) => .andThen((jobs) =>
ResultAsync.combine( ResultAsync.combine(
jobs.map((job) => { jobs.map((job) => {
uploadingFileCard = const cardId = isZipped ? zippedCardId : generateCardId();
uploadingFileCard ?? initCard("uploading", cardId); const uploadingFileCard = isZipped
? zippedUploadingFileCard
: initCard("uploading", cardId);
uploadingFileCard.querySelector(".name").innerText = uploadingFileCard.querySelector(".name").innerText =
job.lufiFile.name; job.lufiFile.name;
@ -258,6 +264,7 @@ document.addEventListener("DOMContentLoaded", () => {
}, 1000); }, 1000);
}); });
} }
uploadedFilesDOM.replaceChild( uploadedFilesDOM.replaceChild(
uploadedFileCard, uploadedFileCard,
uploadingFileCard uploadingFileCard
@ -294,14 +301,14 @@ document.addEventListener("DOMContentLoaded", () => {
return okAsync(job); return okAsync(job);
}) })
.orElse((error) => { .orElse((error) => {
showErrorCard(error, cardId, job.lufiFile); showErrorCard(error, zippedCardId, job.lufiFile);
return errAsync(error); return errAsync(error);
}); });
}) })
) )
) )
.orElse((error) => { .orElse((error) => {
showErrorCard(error, cardId); showErrorCard(error, zippedCardId);
return errAsync(error); return errAsync(error);
}); });
@ -311,20 +318,20 @@ document.addEventListener("DOMContentLoaded", () => {
}; };
if (isZipped) { if (isZipped) {
uploadingFileCard = initCard("uploading", cardId); zippedUploadingFileCard.querySelector(".name").innerText = zipName;
zippedUploadingFileCard.querySelector(".size").innerText =
i18n.unknownYet;
zippedUploadingFileCard.querySelector(".info").innerText =
i18n.compressing;
uploadingFileCard.querySelector(".name").innerText = zipName; uploadedFilesDOM.prepend(zippedUploadingFileCard);
uploadingFileCard.querySelector(".size").innerText = i18n.unknownYet;
uploadingFileCard.querySelector(".info").innerText = i18n.compressing;
uploadedFilesDOM.prepend(uploadingFileCard);
return lufi return lufi
.addFilesToArchive(files) .addFilesToArchive(files)
.andThen((archiveEntries) => lufi.compress(archiveEntries, zipName)) .andThen((archiveEntries) => lufi.compress(archiveEntries, zipName))
.andThen((job) => { .andThen((job) => {
if (uploadingFileCard.querySelector(".name")) { if (zippedUploadingFileCard.querySelector(".name")) {
uploadingFileCard zippedUploadingFileCard
.querySelector("button .delete") .querySelector("button .delete")
.parentNode.addEventListener("click", () => { .parentNode.addEventListener("click", () => {
job.terminate(); job.terminate();
@ -338,7 +345,7 @@ document.addEventListener("DOMContentLoaded", () => {
}) })
.andThen(runUpload) .andThen(runUpload)
.mapErr((error) => { .mapErr((error) => {
showErrorCard(error, cardId); showErrorCard(error, zippedCardId);
}); });
} else { } else {
return runUpload(); return runUpload();