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 } = {}) {
765 */765 */
766async function handleTagImport(character, { importSetting = null } = {}) {766async function handleTagImport(character, { importSetting = null } = {}) {
767 /** @type {string[]} */767 /** @type {string[]} */
768 const alreadyAssignedTags = tag_map[character.avatar] ?? [];
768 const importTags = character.tags.map(t => t.trim()).filter(t => t)769 const importTags = character.tags.map(t => t.trim()).filter(t => t)
769 .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))770 .filter(t => !IMPORT_EXLCUDED_TAGS.includes(t))
771 .filter(t => {
772 const existingTag = getTag(t);
773 return !existingTag || !alreadyAssignedTags.includes(existingTag.id);
774 })
770 .slice(0, ANTI_TROLL_MAX_TAGS);775 .slice(0, ANTI_TROLL_MAX_TAGS);
771 const existingTags = getExistingTags(importTags);776 const existingTags = getExistingTags(importTags);
772 const newTags = importTags.filter(t => !existingTags.some(existingTag => existingTag.name.toLowerCase() === t.toLowerCase()))777 const newTags = importTags.filter(t => !existingTags.some(existingTag => existingTag.name.toLowerCase() === t.toLowerCase()))