FIX: there's no need to try to download relative images

This commit is contained in:
Régis Hanol 2014-09-26 18:27:10 +02:00
parent 8d75ab60ea
commit f283e2a996
1 changed files with 11 additions and 5 deletions

View File

@ -37,12 +37,16 @@ module Jobs
hotlinked = FileHelper.download(src, @max_size, "discourse-hotlinked") hotlinked = FileHelper.download(src, @max_size, "discourse-hotlinked")
rescue Discourse::InvalidParameters rescue Discourse::InvalidParameters
end end
if hotlinked.try(:size) <= @max_size if hotlinked
filename = File.basename(URI.parse(src).path) if hotlinked.size <= @max_size
upload = Upload.create_for(post.user_id, hotlinked, filename, hotlinked.size, { origin: src }) filename = File.basename(URI.parse(src).path)
downloaded_urls[src] = upload.url upload = Upload.create_for(post.user_id, hotlinked, filename, hotlinked.size, { origin: src })
downloaded_urls[src] = upload.url
else
Rails.logger.error("Failed to pull hotlinked image: #{src} - Image is bigger than #{@max_size}")
end
else else
Rails.logger.error("Failed to pull hotlinked image: #{src} - Image is bigger than #{@max_size}") Rails.logger.error("There was an error while downloading '#{src}' locally.")
end end
end end
# have we successfully downloaded that file? # have we successfully downloaded that file?
@ -98,6 +102,8 @@ module Jobs
return false unless src.present? return false unless src.present?
# we don't want to pull uploaded images # we don't want to pull uploaded images
return false if Discourse.store.has_been_uploaded?(src) return false if Discourse.store.has_been_uploaded?(src)
# we don't want to pull relative images
return false if src =~ /\A\/[^\/]/i
# parse the src # parse the src
begin begin
uri = URI.parse(src) uri = URI.parse(src)