diff options
author | RandomChars <random@chars.jp> | 2021-10-02 21:37:28 +0900 |
---|---|---|
committer | RandomChars <random@chars.jp> | 2021-10-02 21:37:28 +0900 |
commit | 76e7c3f0686b5f47bfb0058df62a327d87a08727 (patch) | |
tree | f9b10110ee43e165c6a2894c4dba7db19ef2dd1e | |
parent | 72a329a68c69d2513cbff1ab0ef014e0955a9f5c (diff) |
easier check of tag type validityv1.3.3
-rw-r--r-- | store/tag.go | 26 |
1 files 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) |