From fbddae984507cf5656969e3fdb41a20cd71688f7 Mon Sep 17 00:00:00 2001 From: IceSandwich Date: Tue, 27 Aug 2024 21:02:47 +0800 Subject: [PATCH] fix empty trigger word issue --- js/dragAreaEvent.js | 11 +++++++++-- js/navActions.js | 7 +++++-- ts/dragAreaEvent.ts | 14 +++++++++++--- ts/navActions.ts | 7 +++++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/js/dragAreaEvent.js b/js/dragAreaEvent.js index 5a3ad19..9f4a23f 100644 --- a/js/dragAreaEvent.js +++ b/js/dragAreaEvent.js @@ -93,20 +93,27 @@ dropArea.addEventListener('drop', function (e) { }, false); Promise.all(readTasksSyncPromises).then(function () { var deletedDuplicatedTagCounter = 0; + var deletedEmptyTagCounter = 0; // won't happend actually because has filter when loaded txt file, keep for safe for (const [key, value] of pair.entries()) { if (value.ImgFilename == "" || value.PromptFilename == "") { alert("Cannot find a pair for an instance, skip: \n\tImage: " + value.ImgFilename + "\n\tTxt: " + value.PromptFilename); } else { - const oldSize = value.PromptLists.length; + var oldSize = value.PromptLists.length; value.PromptLists = Array.from(new Set(value.PromptLists)); - storage.push(value); deletedDuplicatedTagCounter += oldSize - value.PromptLists.length; + oldSize = value.PromptLists.length; + value.PromptLists = value.PromptLists.filter(item => item != ""); + deletedEmptyTagCounter += oldSize - value.PromptLists.length; + storage.push(value); } } if (deletedDuplicatedTagCounter > 0) { alert(`Deleted ${deletedDuplicatedTagCounter} duplicated tags!`); } + if (deletedEmptyTagCounter > 0) { + alert(`Deleted ${deletedEmptyTagCounter} empty tags!`); + } var generateTreeNodesPromises = []; for (var i = 0; i < storage.length; i++) { storage[i].PromptLists.forEach(keyword => { diff --git a/js/navActions.js b/js/navActions.js index 9daf261..4ef56c6 100644 --- a/js/navActions.js +++ b/js/navActions.js @@ -123,9 +123,12 @@ function onNavbarExportClick() { return; } const zip = new JSZip(); - const triggerWords = getTriggerWords().join(", "); + let triggerWords = getTriggerWords().join(", "); + if (triggerWords != "") { + triggerWords = triggerWords + ", "; + } storage.forEach((item) => { - const prompt = triggerWords + ", " + item.PromptLists.filter(val => !triggerWords.includes(val)).join(", "); + const prompt = triggerWords + item.PromptLists.filter(val => !triggerWords.includes(val)).join(", "); // const prompt = item.PromptLists.join(", "); const textContent = new TextEncoder().encode(prompt); const blob = new Blob([textContent], { type: "text/plain" }); diff --git a/ts/dragAreaEvent.ts b/ts/dragAreaEvent.ts index d122a37..6c9c954 100644 --- a/ts/dragAreaEvent.ts +++ b/ts/dragAreaEvent.ts @@ -102,20 +102,28 @@ dropArea.addEventListener('drop', function (e) { Promise.all(readTasksSyncPromises).then(function () { var deletedDuplicatedTagCounter = 0; + var deletedEmptyTagCounter = 0; // won't happend actually because has filter when loaded txt file, keep for safe for (const [key, value] of pair.entries()) { if (value.ImgFilename == "" || value.PromptFilename == "") { alert("Cannot find a pair for an instance, skip: \n\tImage: " + value.ImgFilename + "\n\tTxt: " + value.PromptFilename); } else { - const oldSize = value.PromptLists.length; + var oldSize = value.PromptLists.length; value.PromptLists = Array.from(new Set(value.PromptLists)) - storage.push(value); - deletedDuplicatedTagCounter += oldSize - value.PromptLists.length; + + oldSize = value.PromptLists.length; + value.PromptLists = value.PromptLists.filter(item => item != ""); + deletedEmptyTagCounter += oldSize - value.PromptLists.length; + + storage.push(value); } } if (deletedDuplicatedTagCounter > 0) { alert(`Deleted ${deletedDuplicatedTagCounter} duplicated tags!`); } + if (deletedEmptyTagCounter > 0) { + alert(`Deleted ${deletedEmptyTagCounter} empty tags!`); + } var generateTreeNodesPromises = []; diff --git a/ts/navActions.ts b/ts/navActions.ts index a729846..60fb3a2 100644 --- a/ts/navActions.ts +++ b/ts/navActions.ts @@ -132,9 +132,12 @@ function onNavbarExportClick() { } const zip = new JSZip(); - const triggerWords = getTriggerWords().join(", "); + let triggerWords = getTriggerWords().join(", "); + if (triggerWords != "") { + triggerWords = triggerWords + ", "; + } storage.forEach((item) => { - const prompt = triggerWords + ", " + item.PromptLists.filter(val => !triggerWords.includes(val)).join(", "); + const prompt = triggerWords + item.PromptLists.filter(val => !triggerWords.includes(val)).join(", "); // const prompt = item.PromptLists.join(", "); const textContent = new TextEncoder().encode(prompt); const blob = new Blob([textContent], { type: "text/plain" });