Check on existing tag names too

This commit is contained in:
Wolfsblvt 2024-07-28 23:41:28 +02:00
parent c026becb6d
commit 105f54ac72
1 changed files with 13 additions and 6 deletions

View File

@ -1464,12 +1464,19 @@ async function onTagRestoreFileSelect(e) {
continue; continue;
} }
const existingTag = tags.find(x => x.id === tag.id); // Check against both existing id (direct match) and tag with the same name, which is not allowed.
if (existingTag) { let existingTag = tags.find(x => x.id === tag.id);
if (!overwrite) { if (existingTag && !overwrite) {
warnings.push(`Tag with id ${tag.id} already exists.`); warnings.push(`Tag '${tag.name}' with id ${tag.id} already exists.`);
continue; continue;
} }
existingTag = getTag(tag.name);
if (existingTag && !overwrite) {
warnings.push(`Tag with name '${tag.name}' already exists.`);
continue;
}
if (existingTag) {
// On overwrite, we remove and re-add the tag // On overwrite, we remove and re-add the tag
removeFromArray(tags, existingTag); removeFromArray(tags, existingTag);
} }
@ -1491,7 +1498,7 @@ async function onTagRestoreFileSelect(e) {
const groupExists = groups.some(x => String(x.id) === String(key)); const groupExists = groups.some(x => String(x.id) === String(key));
if (!characterExists && !groupExists) { if (!characterExists && !groupExists) {
warnings.push(`Tag map key ${key} does not exist.`); warnings.push(`Tag map key ${key} does not exist as character or group.`);
continue; continue;
} }