FIX: there's no need to try to download relative images
This commit is contained in:
parent
8d75ab60ea
commit
f283e2a996
|
@ -37,13 +37,17 @@ 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
|
||||||
|
if hotlinked.size <= @max_size
|
||||||
filename = File.basename(URI.parse(src).path)
|
filename = File.basename(URI.parse(src).path)
|
||||||
upload = Upload.create_for(post.user_id, hotlinked, filename, hotlinked.size, { origin: src })
|
upload = Upload.create_for(post.user_id, hotlinked, filename, hotlinked.size, { origin: src })
|
||||||
downloaded_urls[src] = upload.url
|
downloaded_urls[src] = upload.url
|
||||||
else
|
else
|
||||||
Rails.logger.error("Failed to pull hotlinked image: #{src} - Image is bigger than #{@max_size}")
|
Rails.logger.error("Failed to pull hotlinked image: #{src} - Image is bigger than #{@max_size}")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error("There was an error while downloading '#{src}' locally.")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# have we successfully downloaded that file?
|
# have we successfully downloaded that file?
|
||||||
if downloaded_urls[src].present?
|
if downloaded_urls[src].present?
|
||||||
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue