This refactors things such that * Fetching the ugoira frame data happens at the end of rewrite, not rewrite_html_pages. This way uploading zip URLs should work. * The source data is cached in an instance variable in case it was indeed fetched during rewrite_html_pages. This way it doesn't get fetched a second time.
32 lines
690 B
Ruby
32 lines
690 B
Ruby
module Downloads
|
|
module RewriteStrategies
|
|
class Base
|
|
def initialize(url = nil)
|
|
@url = url
|
|
end
|
|
|
|
def self.strategies
|
|
[Pixiv, NicoSeiga, Twitpic, DeviantArt, Tumblr, Moebooru]
|
|
end
|
|
|
|
def rewrite(url, headers, data = {})
|
|
return [url, headers, data]
|
|
end
|
|
|
|
protected
|
|
def http_exists?(url, headers)
|
|
exists = false
|
|
uri = URI.parse(url)
|
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
|
http.request_head(uri.request_uri, headers) do |res|
|
|
if res.is_a?(Net::HTTPSuccess)
|
|
exists = true
|
|
end
|
|
end
|
|
end
|
|
exists
|
|
end
|
|
end
|
|
end
|
|
end
|