sources: replace HTTParty with Danbooru::Http in http_exists?.
This commit is contained in:
@@ -147,7 +147,7 @@ module Sources::Strategies
|
||||
urls = urls.reverse
|
||||
end
|
||||
|
||||
chosen_url = urls.find { |url| http_exists?(url, headers) }
|
||||
chosen_url = urls.find { |url| http_exists?(url) }
|
||||
chosen_url || url
|
||||
end
|
||||
end
|
||||
|
||||
@@ -288,9 +288,8 @@ module Sources
|
||||
to_h.to_json
|
||||
end
|
||||
|
||||
def http_exists?(url, headers)
|
||||
res = HTTParty.head(url, Danbooru.config.httparty_options.deep_merge(headers: headers))
|
||||
res.success?
|
||||
def http_exists?(url, headers = {})
|
||||
http.headers(headers).head(url).status.success?
|
||||
end
|
||||
|
||||
# Convert commentary to dtext by stripping html tags. Sites can override
|
||||
|
||||
@@ -168,7 +168,7 @@ module Sources::Strategies
|
||||
end
|
||||
|
||||
candidates.find do |candidate|
|
||||
http_exists?(candidate, headers)
|
||||
http_exists?(candidate)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -16,19 +16,4 @@ module DownloadTestHelper
|
||||
def assert_not_rewritten(source, referer = nil)
|
||||
assert_rewritten(source, source, referer)
|
||||
end
|
||||
|
||||
def assert_http_exists(url, headers: {})
|
||||
res = HTTParty.head(url, Danbooru.config.httparty_options.deep_merge(headers: headers))
|
||||
assert_equal(true, res.success?)
|
||||
end
|
||||
|
||||
def assert_http_status(code, url, headers: {})
|
||||
res = HTTParty.head(url, Danbooru.config.httparty_options.deep_merge(headers: headers))
|
||||
assert_equal(code, res.code)
|
||||
end
|
||||
|
||||
def assert_http_size(size, url, headers: {})
|
||||
res = HTTParty.head(url, Danbooru.config.httparty_options.deep_merge(headers: headers))
|
||||
assert_equal(size, res.content_length)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,7 +43,7 @@ module Sources
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://pic.nijie.net/03/nijie_picture/728995_20170505014820_0.jpg", @site.image_url)
|
||||
assert_http_size(132_555, @site.image_url)
|
||||
assert_downloaded(132_555, @site.image_url)
|
||||
end
|
||||
|
||||
should "get the canonical url" do
|
||||
@@ -53,7 +53,7 @@ module Sources
|
||||
should "get the preview url" do
|
||||
assert_equal("https://pic.nijie.net/03/__rs_l170x170/nijie_picture/728995_20170505014820_0.jpg", @site.preview_url)
|
||||
assert_equal([@site.preview_url], @site.preview_urls)
|
||||
assert_http_exists(@site.preview_url)
|
||||
assert_downloaded(132_555, @site.preview_url)
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
@@ -205,8 +205,8 @@ module Sources
|
||||
assert_equal("https://nijie.info/members.php?id=236014", site.profile_url)
|
||||
assert_nothing_raised { site.to_h }
|
||||
|
||||
assert_http_size(3619, site.image_url)
|
||||
assert_http_exists(site.preview_url)
|
||||
assert_downloaded(3619, site.image_url)
|
||||
assert_downloaded(3619, site.preview_url)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user