fix: prevent duplicate tag imports by filtering already assigned tags, fixing an unintended error toast (#4582)

1d1b606f729630ca3622021593ba42daa5811d86

Wolfsblvt <wolfsblvt@gmail.com>

Signed
1 files changed, +5 -0Showing whitespace changes
public/scripts/tags.js+5 -0
@@ -765,8 +765,13 @@ async function importTags(character, { importSetting = null } = {}) {
765765 */
766766async function handleTagImport(character, { importSetting = null } = {}) {
767767 /** @type {string[]} */
768+ const alreadyAssignedTags = tag_map[character.avatar] ?? [];
768769 const importTags = character.tags.map(t => t.trim()).filter(t => t)
769770 .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
771+ .filter(t => {
772+ const existingTag = getTag(t);
773+ return !existingTag || !alreadyAssignedTags.includes(existingTag.id);
774+ })
770775 .slice(0, ANTI_TROLL_MAX_TAGS);
771776 const existingTags = getExistingTags(importTags);
772777 const newTags = importTags.filter(t => !existingTags.some(existingTag => existingTag.name.toLowerCase() === t.toLowerCase()))