[UploadPresenter] Normalize tags & strip metatags

This commit is contained in:
Donovan Daniels 2024-04-05 23:29:19 -05:00
parent f5fcd8a53b
commit 5edbb507b6
No known key found for this signature in database
GPG Key ID: 907D29CBFD6157BA
2 changed files with 12 additions and 1 deletions

View File

@ -105,4 +105,5 @@ class TagCategory
CATEGORIZED_LIST = %w[invalid artist copyright character species meta general lore].freeze
SHORT_NAME_REGEX = SHORT_NAME_LIST.join("|").freeze
ALL_NAMES_REGEX = MAPPING.keys.join("|").freeze
end

View File

@ -7,6 +7,16 @@ class UploadPresenter < Presenter
end
def tag_set_presenter
@tag_set_presenter ||= TagSetPresenter.new(upload.tag_string.split)
@tag_set_presenter ||= TagSetPresenter.new(normalize_tags(upload.tag_string.split))
end
def strip_metatags(tags)
tags.grep_v(/\A(?:rating|-?parent|-?locked|-?pool|newpool|-?set|-?fav|-?child|upvote|downvote):/i)
end
def normalize_tags(tags)
tags = tags.map(&:downcase)
tags = strip_metatags(tags)
tags.map { |tag| tag.gsub(/(?:#{TagCategory::ALL_NAMES_REGEX}):/, "") }
end
end