sources: remove canonical_url method.
Refactor source strategies to remove the `canonical_url` method. `canonical_url` returned the URL that should be used as the source of the post after upload. Now we simply use `Source::URL#page_url` to determine the source after upload. If the source is an image URL that is convertible to a page URL, then the image URL is used as the source. If the source is an image URL that is not convertible to a page URL, then the page URL is used as the source. This simplifies source strategies so that all they have to care about is implementing the `Source::URL#page_url` and `Sources::Strategies#page_url` methods, and the preferred source will be chosen for posts automatically.
This commit is contained in:
@@ -31,9 +31,5 @@ module Sources
|
||||
strategy = all.lazy.map { |s| s.new(url, referer) }.detect(&:match?)
|
||||
strategy || default&.new(url, referer)
|
||||
end
|
||||
|
||||
def self.canonical(url, referer)
|
||||
find(url, referer).canonical_url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,20 +65,23 @@ module Sources
|
||||
[]
|
||||
end
|
||||
|
||||
# Whatever <tt>url</tt> is, this method should return a link to the HTML
|
||||
# page containing the resource. It should not be a binary file. It will
|
||||
# eventually be assigned as the source for the post, but it does not
|
||||
# represent what the downloader will fetch.
|
||||
# The URL of the page containing the image, or nil if it can't be found.
|
||||
#
|
||||
# The source of the post will be set to the page URL if it's not possible
|
||||
# to convert the image URL to a page URL for this site.
|
||||
#
|
||||
# For example, for sites like Twitter and Tumblr, it's not possible to
|
||||
# convert image URLs to page URLs, so the page URL will be used as the
|
||||
# source for these sites. For sites like Pixiv and DeviantArt, it is
|
||||
# possible to convert image URLs to page URLs, so the image URL will be
|
||||
# used as the source for these sites. This is determined by whether
|
||||
# `Source::URL#page_url` returns a URL or nil.
|
||||
#
|
||||
# @return [String, nil]
|
||||
def page_url
|
||||
nil
|
||||
end
|
||||
|
||||
# This will be the url stored in posts. Typically this is the page
|
||||
# url, but on some sites it may be preferable to store the image url.
|
||||
def canonical_url
|
||||
page_url || image_urls.first
|
||||
end
|
||||
|
||||
# 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
|
||||
@@ -197,7 +200,7 @@ module Sources
|
||||
# uploaded from the same source. These may be duplicates, or they may be
|
||||
# other posts from the same gallery.
|
||||
def related_posts_search_query
|
||||
"source:#{canonical_url}"
|
||||
"source:#{url}"
|
||||
end
|
||||
|
||||
def related_posts(limit = 5)
|
||||
@@ -222,7 +225,6 @@ module Sources
|
||||
:artists => artists.as_json(include: :sorted_urls),
|
||||
:image_urls => image_urls,
|
||||
:page_url => page_url,
|
||||
:canonical_url => canonical_url,
|
||||
:tags => tags,
|
||||
:normalized_tags => normalized_tags,
|
||||
:translated_tags => translated_tags,
|
||||
|
||||
@@ -47,10 +47,6 @@ module Sources
|
||||
parsed_url.username || parsed_referer&.username
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def profile_url
|
||||
return nil if artist_name.blank?
|
||||
"https://www.hentai-foundry.com/user/#{artist_name}"
|
||||
|
||||
@@ -21,10 +21,6 @@ module Sources
|
||||
"https://#{domain}/post/show/#{post_id}"
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def tags
|
||||
api_response[:tags].to_s.split.map do |tag|
|
||||
[tag, "https://#{domain}/post?tags=#{CGI.escape(tag)}"]
|
||||
|
||||
@@ -75,15 +75,6 @@ module Sources
|
||||
DText.from_html(artist_commentary_desc)
|
||||
end
|
||||
|
||||
# The image url should be the post source, if we can generate the page url from the image url.
|
||||
def canonical_url
|
||||
if page_url.present?
|
||||
url
|
||||
else
|
||||
page_url
|
||||
end
|
||||
end
|
||||
|
||||
def user_name
|
||||
parsed_url.username || parsed_referer&.username
|
||||
end
|
||||
|
||||
@@ -11,10 +11,6 @@ module Sources
|
||||
nil
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
url
|
||||
end
|
||||
|
||||
def artists
|
||||
ArtistFinder.find_artists(url)
|
||||
end
|
||||
|
||||
@@ -57,10 +57,6 @@ module Sources
|
||||
"https://www.pixiv.net/artworks/#{illust_id}"
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def profile_url
|
||||
if api_illust[:userId].present?
|
||||
"https://www.pixiv.net/users/#{api_illust[:userId]}"
|
||||
@@ -128,7 +124,7 @@ module Sources
|
||||
end
|
||||
|
||||
def related_posts_search_query
|
||||
illust_id.present? ? "pixiv:#{illust_id}" : "source:#{canonical_url}"
|
||||
illust_id.present? ? "pixiv:#{illust_id}" : "source:#{url}"
|
||||
end
|
||||
|
||||
def is_ugoira?
|
||||
|
||||
Reference in New Issue
Block a user