From f283e2a996b6e399120eb4c882ce89d5a83bb1a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 26 Sep 2014 18:27:10 +0200 Subject: [PATCH] FIX: there's no need to try to download relative images --- app/jobs/regular/pull_hotlinked_images.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb index a2d42a752dd..9ad4e8cf4ad 100644 --- a/app/jobs/regular/pull_hotlinked_images.rb +++ b/app/jobs/regular/pull_hotlinked_images.rb @@ -37,12 +37,16 @@ module Jobs hotlinked = FileHelper.download(src, @max_size, "discourse-hotlinked") rescue Discourse::InvalidParameters end - if hotlinked.try(:size) <= @max_size - filename = File.basename(URI.parse(src).path) - upload = Upload.create_for(post.user_id, hotlinked, filename, hotlinked.size, { origin: src }) - downloaded_urls[src] = upload.url + if hotlinked + if hotlinked.size <= @max_size + filename = File.basename(URI.parse(src).path) + 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 - 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 # have we successfully downloaded that file? @@ -98,6 +102,8 @@ module Jobs return false unless src.present? # we don't want to pull uploaded images 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 begin uri = URI.parse(src)