|
|
|
@ -35,16 +35,16 @@ module DownloadUtils
|
|
|
|
|
|
|
|
|
|
|
|
module_function
|
|
|
|
module_function
|
|
|
|
|
|
|
|
|
|
|
|
def call(url)
|
|
|
|
def call(url, validate: Docuseal.multitenant?)
|
|
|
|
uri = begin
|
|
|
|
uri = begin
|
|
|
|
URI(url)
|
|
|
|
URI(url)
|
|
|
|
rescue URI::Error
|
|
|
|
rescue URI::Error
|
|
|
|
Addressable::URI.parse(url).normalize
|
|
|
|
Addressable::URI.parse(url).normalize
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
validate_uri!(uri) if Docuseal.multitenant?
|
|
|
|
validate_uri!(uri) if validate
|
|
|
|
|
|
|
|
|
|
|
|
resp = conn.get(uri)
|
|
|
|
resp = conn(validate:).get(uri)
|
|
|
|
|
|
|
|
|
|
|
|
raise UnableToDownload, "Error loading: #{uri}" if resp.status >= 400
|
|
|
|
raise UnableToDownload, "Error loading: #{uri}" if resp.status >= 400
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,10 +56,10 @@ module DownloadUtils
|
|
|
|
raise UnableToDownload, "Error loading: #{uri}. Can't download from localhost." if uri.host.in?(LOCALHOSTS)
|
|
|
|
raise UnableToDownload, "Error loading: #{uri}. Can't download from localhost." if uri.host.in?(LOCALHOSTS)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def conn
|
|
|
|
def conn(validate: Docuseal.multitenant?)
|
|
|
|
Faraday.new do |faraday|
|
|
|
|
Faraday.new do |faraday|
|
|
|
|
faraday.response :follow_redirects, callback: lambda { |_, new_env|
|
|
|
|
faraday.response :follow_redirects, callback: lambda { |_, new_env|
|
|
|
|
validate_uri!(new_env[:url]) if Docuseal.multitenant?
|
|
|
|
validate_uri!(new_env[:url]) if validate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|