add more logs to pull hotlinked images

This commit is contained in:
Régis Hanol 2017-09-28 01:00:13 +02:00
parent dd07094bd7
commit 3a75242c38
2 changed files with 14 additions and 2 deletions

View File

@ -44,6 +44,7 @@ module Jobs
follow_redirect: true
)
rescue Discourse::InvalidParameters
log(:error, "InvalidParameters while downloading hotlinked image (#{src}) for post: #{post_id}")
end
if hotlinked
if File.size(hotlinked.path) <= @max_size
@ -87,7 +88,7 @@ module Jobs
raw.gsub!(/^#{escaped_src}(\s?)$/) { "<img src='#{url}'>#{$1}" }
end
rescue => e
log(:error, "Failed to pull hotlinked image: #{src} post:#{post_id}\n" + e.message + "\n" + e.backtrace.join("\n"))
log(:error, "Failed to pull hotlinked image (#{src}) post: #{post_id}\n" + e.message + "\n" + e.backtrace.join("\n"))
end
end

View File

@ -4,6 +4,13 @@ require "open-uri"
class FileHelper
def self.log(log_level, message)
Rails.logger.public_send(
log_level,
"#{RailsMultisite::ConnectionManagement.current_db}: #{message}"
)
end
def self.is_image?(filename)
filename =~ images_regexp
end
@ -23,7 +30,11 @@ class FileHelper
max_redirects: follow_redirect ? 5 : 1,
skip_rate_limit: skip_rate_limit
).resolve
return unless uri.present?
unless uri.present?
log(:error, "FinalDestination did not work for: #{url}")
return
end
downloaded = uri.open("rb", read_timeout: read_timeout)