sources: remove image_url method from base strategy.
Remove the `image_url` method from source strategies. This method would return only the first image if a source had multiple images. The `image_urls` method should be used instead. Tests were the main place that still used `image_url` instead of `image_urls`. Also make post replacements return an error if replacing with a source that contains multiple images, instead of just blindly replacing the post with the first image in the source.
This commit is contained in:
@@ -67,6 +67,9 @@ class PostReplacementProcessor
|
||||
strategy = Sources::Strategies.find(source_url, referer_url)
|
||||
raise NotImplementedError, "No login credentials configured for #{strategy.site_name}." unless strategy.class.enabled?
|
||||
|
||||
strategy.download_file!
|
||||
image_urls = strategy.image_urls
|
||||
raise "#{source_url} contains multiple images" if image_urls.size > 1
|
||||
|
||||
strategy.download_file!(image_urls.first)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -129,10 +129,6 @@ module Sources
|
||||
[]
|
||||
end
|
||||
|
||||
def image_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
# A smaller representation of the image that's suitable for
|
||||
# displaying previews.
|
||||
def preview_urls
|
||||
@@ -154,7 +150,7 @@ module Sources
|
||||
# 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_url
|
||||
page_url || image_urls.first
|
||||
end
|
||||
|
||||
# A name to suggest as the artist's tag name when creating a new artist.
|
||||
@@ -194,8 +190,11 @@ module Sources
|
||||
nil
|
||||
end
|
||||
|
||||
# Download the file at the given url, or at the main image url by default.
|
||||
def download_file!(download_url = image_url)
|
||||
# Download the file at the given url. Raises Danbooru::Http::DownloadError if the download fails, or
|
||||
# Danbooru::Http::FileTooLargeError if the file is too large.
|
||||
#
|
||||
# @return [MediaFile] the downloaded file
|
||||
def download_file!(download_url)
|
||||
response, file = http_downloader.download_media(download_url)
|
||||
file
|
||||
end
|
||||
@@ -310,7 +309,6 @@ module Sources
|
||||
:profile_urls => profile_urls
|
||||
},
|
||||
:artists => artists.as_json(include: :sorted_urls),
|
||||
:image_url => image_url,
|
||||
:image_urls => image_urls,
|
||||
:preview_url => preview_url,
|
||||
:preview_urls => preview_urls,
|
||||
|
||||
@@ -58,7 +58,7 @@ module Sources
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def profile_url
|
||||
|
||||
@@ -18,10 +18,6 @@ module Sources::Strategies
|
||||
end
|
||||
end
|
||||
|
||||
def image_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def image_urls
|
||||
if parsed_url.image_url?
|
||||
[parsed_url.full_image_url]
|
||||
|
||||
@@ -27,7 +27,7 @@ module Sources
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def normalize_for_source
|
||||
|
||||
@@ -12,7 +12,7 @@ module Sources
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_url
|
||||
url
|
||||
end
|
||||
|
||||
def normalize_for_source
|
||||
|
||||
@@ -62,7 +62,7 @@ module Sources
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def profile_url
|
||||
@@ -122,7 +122,7 @@ module Sources
|
||||
tag.gsub(/\d+users入り\z/i, "")
|
||||
end
|
||||
|
||||
def download_file!(url = image_url)
|
||||
def download_file!(url)
|
||||
file = super(url)
|
||||
file.frame_data = ugoira_frame_data if is_ugoira?
|
||||
file
|
||||
|
||||
Reference in New Issue
Block a user