From 76e7c3f0686b5f47bfb0058df62a327d87a08727 Mon Sep 17 00:00:00 2001
From: RandomChars <random@chars.jp>
Date: Sat, 2 Oct 2021 21:37:28 +0900
Subject: [PATCH] easier check of tag type validity

---
 store/tag.go | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/store/tag.go b/store/tag.go
index 1e92630..368bdd3 100644
--- a/store/tag.go
+++ b/store/tag.go
@@ -21,6 +21,23 @@ const (
 	GenericType = "generic"
 )
 
+var (
+	// AllowedTagTypes represent tag type strings that are allowed.
+	AllowedTagTypes    = []string{ArtistType, CharacterType, CopyrightType, MetaType, GenericType}
+	allowedTagTypesMap = map[string]bool{
+		ArtistType:    true,
+		CharacterType: true,
+		CopyrightType: true,
+		MetaType:      true,
+		GenericType:   true,
+	}
+)
+
+// TagTypeAllowed returns whether str is an allowed tag type.
+func TagTypeAllowed(str string) bool {
+	return allowedTagTypesMap[str]
+}
+
 // Tag represents metadata of a tag.
 type Tag struct {
 	Type         string    `json:"type"`
@@ -131,13 +148,8 @@ func (s *Store) TagType(tag, t string) {
 		return
 	}
 
-	if t != ArtistType &&
-		t != CharacterType &&
-		t != CopyrightType &&
-		t != GenericType &&
-		t != MetaType {
-		log.Warnf("Invalid tag change on tag %s, got %s, expecting {%s,%s,%s,%s,%s}", tag, t,
-			ArtistType, CharacterType, CopyrightType, GenericType, MetaType)
+	if !TagTypeAllowed(t) {
+		log.Warnf("Invalid tag change on tag %s, got %s, expecting %s", tag, t, AllowedTagTypes)
 		return
 	}
 	info := s.TagInfo(tag)
-- 
GitLab