diff options
author | Jenkins <jenkins@jenkins.ninjawedding.org> | 2018-03-25 15:17:21 +0000 |
---|---|---|
committer | Jenkins <jenkins@jenkins.ninjawedding.org> | 2018-03-25 15:17:21 +0000 |
commit | 837b3804bfed9db1cf92923c4f6202aa7117d408 (patch) | |
tree | c8b5a921754a6b40227364225002332b54d0d0dd /app/models/concerns | |
parent | 995b59526b06e1f949cba59d76e5e2718a1674f6 (diff) | |
parent | 85a395fab6d7077a252bfe6f96673931ea3aa5ee (diff) |
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/remotable.rb | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/app/models/concerns/remotable.rb b/app/models/concerns/remotable.rb index 69685ec83..0f18c5d96 100644 --- a/app/models/concerns/remotable.rb +++ b/app/models/concerns/remotable.rb @@ -21,23 +21,23 @@ module Remotable return if !%w(http https).include?(parsed_url.scheme) || parsed_url.host.empty? || self[attribute_name] == url begin - response = Request.new(:get, url).perform - - return if response.code != 200 - - matches = response.headers['content-disposition']&.match(/filename="([^"]*)"/) - filename = matches.nil? ? parsed_url.path.split('/').last : matches[1] - basename = SecureRandom.hex(8) - extname = if filename.nil? - '' - else - File.extname(filename) - end - - send("#{attachment_name}=", StringIO.new(response.to_s)) - send("#{attachment_name}_file_name=", basename + extname) - - self[attribute_name] = url if has_attribute?(attribute_name) + Request.new(:get, url).perform do |response| + next if response.code != 200 + + matches = response.headers['content-disposition']&.match(/filename="([^"]*)"/) + filename = matches.nil? ? parsed_url.path.split('/').last : matches[1] + basename = SecureRandom.hex(8) + extname = if filename.nil? + '' + else + File.extname(filename) + end + + send("#{attachment_name}=", StringIO.new(response.to_s)) + send("#{attachment_name}_file_name=", basename + extname) + + self[attribute_name] = url if has_attribute?(attribute_name) + end rescue HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError, Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError => e Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}" nil |