mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
add more logs to pull hotlinked images
This commit is contained in:
parent
dd07094bd7
commit
3a75242c38
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user