From 1f73e6051408b6e819d8da0a9bd2ba06f899c4d9 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 27 Dec 2018 15:03:11 -0600 Subject: [PATCH] sources: add methods for customizing new artist entries. * Rename `unique_id` to `tag_name`. * Add `other_names` and `profile_urls` methods that sources can override to provide extra names or urls when creating new artist entries. --- app/logical/sources/strategies/base.rb | 49 ++++++++++++++------ app/logical/sources/strategies/moebooru.rb | 2 +- app/logical/sources/strategies/nico_seiga.rb | 2 +- app/logical/sources/strategies/nijie.rb | 2 +- app/logical/sources/strategies/null.rb | 4 -- app/logical/sources/strategies/pixiv.rb | 2 +- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/logical/sources/strategies/base.rb b/app/logical/sources/strategies/base.rb index 329f87c71..918a10e13 100644 --- a/app/logical/sources/strategies/base.rb +++ b/app/logical/sources/strategies/base.rb @@ -101,13 +101,33 @@ module Sources page_url || image_url end - # A link to the artist's profile page on the site. - def profile_url - "" + # A name to suggest as the artist's tag name when creating a new artist. + # This should usually be the artist's account name. + def tag_name + artist_name end + # The artists's primary name. If an artist has both a display name and an + # account name, this should be the display name. def artist_name - "" + nil + end + + # A list of all names associated with the artist. These names will be suggested + # as other names when creating a new artist. + def other_names + [artist_name, tag_name].compact.uniq + end + + # A link to the artist's profile page on the site. + def profile_url + nil + end + + # A list of all profile urls associated with the artist. These urls will + # be suggested when creating a new artist. + def profile_urls + [normalize_for_artist_finder] end def artist_commentary_title @@ -157,11 +177,6 @@ module Sources profile_url.presence || url end - # A unique identifier for the artist. This is used for artist creation. - def unique_id - artist_name - end - def artists Artist.find_artists(normalize_for_artist_finder) end @@ -170,9 +185,9 @@ module Sources # exist. Used in Artist.new_with_defaults to prefill the new artist form. def new_artist Artist.new( - name: unique_id, - other_names: [artist_name], - url_string: [profile_url, normalize_for_artist_finder].sort.uniq.join("\n") + name: tag_name, + other_names: other_names, + url_string: profile_urls.join("\n") ) end @@ -249,9 +264,14 @@ module Sources def to_h return { - :artist_name => artist_name, + :artist => { + :name => artist_name, + :tag_name => tag_name, + :other_names => other_names, + :profile_url => profile_url, + :profile_urls => profile_urls, + }, :artists => artists.as_json(include: :sorted_urls), - :profile_url => profile_url, :image_url => image_url, :image_urls => image_urls, :page_url => page_url, @@ -260,7 +280,6 @@ module Sources :tags => tags, :normalized_tags => normalized_tags, :translated_tags => translated_tags, - :unique_id => unique_id, :artist_commentary => { :title => artist_commentary_title, :description => artist_commentary_desc, diff --git a/app/logical/sources/strategies/moebooru.rb b/app/logical/sources/strategies/moebooru.rb index cdeb82d9e..27dd9d424 100644 --- a/app/logical/sources/strategies/moebooru.rb +++ b/app/logical/sources/strategies/moebooru.rb @@ -36,7 +36,7 @@ module Sources URL_SLUG = %r!/(?:yande\.re%20|Konachan\.com%20-%20)(?\d+).*!i IMAGE_URL = %r!#{BASE_URL}/(?image|jpeg|sample)/(?\h{32})#{URL_SLUG}?\.(?jpg|jpeg|png|gif)\z!i - delegate :artist_name, :profile_url, :unique_id, :artist_commentary_title, :artist_commentary_desc, :dtext_artist_commentary_title, :dtext_artist_commentary_desc, to: :sub_strategy, allow_nil: true + delegate :artist_name, :profile_url, :tag_name, :artist_commentary_title, :artist_commentary_desc, :dtext_artist_commentary_title, :dtext_artist_commentary_desc, to: :sub_strategy, allow_nil: true def domains ["yande.re", "konachan.com"] diff --git a/app/logical/sources/strategies/nico_seiga.rb b/app/logical/sources/strategies/nico_seiga.rb index 98db31891..a5534321c 100644 --- a/app/logical/sources/strategies/nico_seiga.rb +++ b/app/logical/sources/strategies/nico_seiga.rb @@ -112,7 +112,7 @@ module Sources "#{profile_url}/" end - def unique_id + def tag_name "nicoseiga#{api_client.user_id}" end diff --git a/app/logical/sources/strategies/nijie.rb b/app/logical/sources/strategies/nijie.rb index 633e5efb9..5720d7725 100644 --- a/app/logical/sources/strategies/nijie.rb +++ b/app/logical/sources/strategies/nijie.rb @@ -123,7 +123,7 @@ module Sources end end - def unique_id + def tag_name "nijie" + artist_id.to_s end diff --git a/app/logical/sources/strategies/null.rb b/app/logical/sources/strategies/null.rb index 23cc860ad..38fd16dbd 100644 --- a/app/logical/sources/strategies/null.rb +++ b/app/logical/sources/strategies/null.rb @@ -24,10 +24,6 @@ module Sources def normalize_for_artist_finder url end - - def unique_id - url - end end end end diff --git a/app/logical/sources/strategies/pixiv.rb b/app/logical/sources/strategies/pixiv.rb index 4179b2cc5..664d95936 100644 --- a/app/logical/sources/strategies/pixiv.rb +++ b/app/logical/sources/strategies/pixiv.rb @@ -149,7 +149,7 @@ module Sources illust_id.present? || novel_id.present? || fanbox_id.present? || fanbox_account_id.present? end - def unique_id + def tag_name moniker end