deviantart: fix sample urls not being rewritten to full size urls.

This commit is contained in:
evazion
2018-09-02 15:48:34 -05:00
parent 807c3dd5f4
commit 2d1b1311d6
2 changed files with 19 additions and 20 deletions

View File

@@ -18,32 +18,24 @@ module Sources
end
def image_urls
# return direct links
if url =~ ATTRIBUTED_ASSET || url =~ ASSET
return [url]
end
# work is deleted, use image url as given by user.
if uuid.nil?
return [url]
end
# work is private or deleted, use image url as given by user.
if api_deviation.blank?
[url]
# work is downloadable
if api_deviation[:is_downloadable] && api_deviation[:download_filesize] != api_deviation.dig(:content, :filesize)
elsif api_deviation[:is_downloadable] && api_deviation[:download_filesize] != api_deviation.dig(:content, :filesize)
src = api_download[:src]
src.gsub!(%r!\Ahttps?://s3\.amazonaws\.com/!i, "https://")
src.gsub!(/\?.*\z/, "") # strip s3 query params
src.gsub!(%r!\Ahttps://origin-orig\.deviantart\.net!, "http://origin-orig.deviantart.net") # https://origin-orig.devianart.net doesn't work
return [src]
end
[src]
# work isn't downloadable, or download size is same as regular size.
if api_deviation.present?
return [api_deviation.dig(:content, :src)]
elsif api_deviation.present?
src = api_deviation.dig(:content, :src)
src = src.gsub(%r!\Ahttps?://orig\d+\.deviantart\.net!i, "http://origin-orig.deviantart.net")
[src]
else
raise "Couldn't find image url" # this should never happen
end
raise "Couldn't find image url"
end
def page_url

View File

@@ -40,7 +40,7 @@ module Sources
assert_equal("hideyoshi", @site.artist_name)
assert_equal("https://www.deviantart.com/hideyoshi", @site.profile_url)
assert_equal("https://pre00.deviantart.net/b5e6/th/pre/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg", @site.image_url)
assert_equal("http://origin-orig.deviantart.net/9e1f/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg", @site.image_url)
end
end
@@ -56,6 +56,13 @@ module Sources
end
end
context "The source for a img00.deviantart.net sample image url" do
should "return the full size image url" do
@site = Sources::Strategies.find("https://img00.deviantart.net/a233/i/2017/160/5/1/test_post_please_ignore_by_noizave-dbc3a48.png")
assert_equal("http://origin-orig.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png", @site.image_url)
end
end
context "The source for a th00.deviantart.net/*/PRE/* thumbnail url" do
should "return the full size image url" do
@site = Sources::Strategies.find("http://th00.deviantart.net/fs71/PRE/f/2014/065/3/b/goruto_by_xyelkiltrox-d797tit.png")