fix url download

pull/402/merge
Pete Matsyburka 1 month ago
parent 7a2c37454e
commit 9377766e52

@ -56,7 +56,7 @@ class TemplatesUploadsController < ApplicationController
def create_file_params_from_url
tempfile = Tempfile.new
tempfile.binmode
tempfile.write(DownloadUtils.call(params[:url]).body)
tempfile.write(DownloadUtils.call(params[:url], validate: true).body)
tempfile.rewind
filename = URI.decode_www_form_component(params[:filename]) if params[:filename].present?

@ -35,16 +35,16 @@ module DownloadUtils
module_function
def call(url)
def call(url, validate: Docuseal.multitenant?)
uri = begin
URI(url)
rescue URI::Error
Addressable::URI.parse(url).normalize
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
@ -56,10 +56,10 @@ module DownloadUtils
raise UnableToDownload, "Error loading: #{uri}. Can't download from localhost." if uri.host.in?(LOCALHOSTS)
end
def conn
def conn(validate: Docuseal.multitenant?)
Faraday.new do |faraday|
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

@ -236,7 +236,7 @@ module Submitters
return blob if blob
data = DownloadUtils.call(url).body
data = DownloadUtils.call(url, validate: true).body
checksum = Digest::MD5.base64digest(data)

Loading…
Cancel
Save