Log an error when we can't reach an image to get its dimensions

This commit is contained in:
Régis Hanol 2015-08-07 19:31:15 +02:00
parent 1aa075f70b
commit 485d9a5a52
1 changed files with 11 additions and 0 deletions

View File

@ -107,13 +107,18 @@ class CookedPostProcessor
end
def get_size(url)
return @size_cache[url] if @size_cache.has_key?(url)
absolute_url = url
absolute_url = Discourse.base_url_no_prefix + absolute_url if absolute_url =~ /^\/[^\/]/
# FastImage fails when there's no scheme
absolute_url = SiteSetting.scheme + ":" + absolute_url if absolute_url.start_with?("//")
return unless is_valid_image_url?(absolute_url)
# we can *always* crawl our own images
return unless SiteSetting.crawl_images? || Discourse.store.has_been_uploaded?(url)
@size_cache[url] ||= FastImage.size(absolute_url)
rescue Zlib::BufError # FastImage.size raises BufError for some gifs
end
@ -131,6 +136,12 @@ class CookedPostProcessor
width, height = img["width"].to_i, img["height"].to_i
original_width, original_height = get_size(src)
# can't reach the image...
if original_width.nil? || original_height.nil?
Rails.logger.error "Can't reach '#{src}' to get its dimension."
return
end
return if original_width.to_i <= width && original_height.to_i <= height
return if original_width.to_i <= SiteSetting.max_image_width && original_height.to_i <= SiteSetting.max_image_height