From 57ebc48e28a6688c5e07235b3ead6856575a88c9 Mon Sep 17 00:00:00 2001 From: RandomChars <random@chars.jp> Date: Sat, 11 Sep 2021 10:19:38 +0900 Subject: [PATCH] rename tag constants, remove unused tag type --- store/misc.go | 15 --------------- store/tag.go | 30 +++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/store/misc.go b/store/misc.go index fd5f474..a137198 100644 --- a/store/misc.go +++ b/store/misc.go @@ -7,21 +7,6 @@ import ( const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" -const ( - // Artist is the tag type artist. - Artist = "artist" - // Character is the tag type character. - Character = "character" - // Copyright is the tag type copyright. - Copyright = "copyright" - // Generic is the tag type generic. - Generic = "generic" - // Group is the tag type group. - Group = "group" - // Meta is the tag type meta. - Meta = "meta" -) - var ( nameRegex = regexp.MustCompile(`^[a-z0-9()_-]{3,}$`) sha256Regex = regexp.MustCompile(`\b[A-Fa-f0-9]{64}\b`) diff --git a/store/tag.go b/store/tag.go index dc9073f..580cd12 100644 --- a/store/tag.go +++ b/store/tag.go @@ -8,6 +8,19 @@ import ( "time" ) +const ( + // ArtistType is the tag type artist. + ArtistType = "artist" + // CharacterType is the tag type character. + CharacterType = "character" + // CopyrightType is the tag type copyright. + CopyrightType = "copyright" + // MetaType is the tag type meta. + MetaType = "meta" + // GenericType is the tag type generic. + GenericType = "generic" +) + // Tag represents metadata of a tag. type Tag struct { Type string `json:"type"` @@ -59,7 +72,7 @@ func (s *Store) TagCreate(tag string) bool { if err := os.Mkdir(s.TagPath(tag), s.PermissionDir); err != nil { s.fatalClose(fmt.Sprintf("Error creating tag %s, %s", tag, err)) } - if payload, err := json.Marshal(Tag{Type: Generic, CreationTime: time.Now().UTC()}); err != nil { + if payload, err := json.Marshal(Tag{Type: GenericType, CreationTime: time.Now().UTC()}); err != nil { s.fatalClose(fmt.Sprintf("Error generating tag %s metadata, %s", tag, err)) } else { if err = os.WriteFile(s.TagMetadataPath(tag), payload, s.PermissionFile); err != nil { @@ -121,14 +134,13 @@ func (s *Store) TagType(tag, t string) { s.getLock("tag_" + tag).Lock() defer s.getLock("tag_" + tag).Unlock() - if t != Artist && - t != Character && - t != Copyright && - t != Generic && - t != Group && - t != Meta { - log.Warnf("Invalid tag change on tag %s, got %s, expecting {%s,%s,%s,%s,%s,%s}", tag, t, - Artist, Character, Copyright, Generic, Group, Meta) + 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) return } info := s.TagInfo(tag) -- GitLab