|
|
|
@ -8,19 +8,20 @@ module DownloadUtils
|
|
|
|
module_function
|
|
|
|
module_function
|
|
|
|
|
|
|
|
|
|
|
|
def call(url)
|
|
|
|
def call(url)
|
|
|
|
uri = Addressable::URI.parse(url)
|
|
|
|
uri = begin
|
|
|
|
|
|
|
|
URI(url)
|
|
|
|
|
|
|
|
rescue URI::Error
|
|
|
|
|
|
|
|
Addressable::URI.parse(url).normalize
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if Docuseal.multitenant?
|
|
|
|
if Docuseal.multitenant?
|
|
|
|
raise UnableToDownload, "Error loading: #{uri.display_uri}. Only HTTPS is allowed." if uri.scheme != 'https'
|
|
|
|
raise UnableToDownload, "Error loading: #{uri}. Only HTTPS is allowed." if uri.scheme != 'https'
|
|
|
|
|
|
|
|
raise UnableToDownload, "Error loading: #{uri}. Can't download from localhost." if uri.host.in?(LOCALHOSTS)
|
|
|
|
if uri.host.in?(LOCALHOSTS)
|
|
|
|
|
|
|
|
raise UnableToDownload, "Error loading: #{uri.display_uri}. Can't download from localhost."
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
resp = conn.get(uri.display_uri.to_s)
|
|
|
|
resp = conn.get(uri)
|
|
|
|
|
|
|
|
|
|
|
|
raise UnableToDownload, "Error loading: #{uri.display_uri}" if resp.status >= 400
|
|
|
|
raise UnableToDownload, "Error loading: #{uri}" if resp.status >= 400
|
|
|
|
|
|
|
|
|
|
|
|
resp
|
|
|
|
resp
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|