diff --git a/lib/docs/filters/core/images.rb b/lib/docs/filters/core/images.rb index d88b65cd..f099afe8 100644 --- a/lib/docs/filters/core/images.rb +++ b/lib/docs/filters/core/images.rb @@ -4,6 +4,8 @@ module Docs class ImagesFilter < Filter include Instrumentable + DEFAULT_MAX_SIZE = 120_000 # 120 kilobytes + def self.optimize_image_data(data) @image_optim ||= ImageOptim.new @image_optim.optimize_image_data(data) @@ -48,7 +50,7 @@ module Docs size = image.bytesize - if size > max_size + if size > (context[:max_image_size] || DEFAULT_MAX_SIZE) instrument 'too_big.image', url: url, size: size next end @@ -64,11 +66,5 @@ module Docs doc end - - private - - def max_size - @max_size ||= context[:max_image_size] || 100.kilobytes - end end end diff --git a/lib/docs/subscribers/image_subscriber.rb b/lib/docs/subscribers/image_subscriber.rb index 918c8880..907b873e 100644 --- a/lib/docs/subscribers/image_subscriber.rb +++ b/lib/docs/subscribers/image_subscriber.rb @@ -13,7 +13,7 @@ module Docs end def too_big(event) - log "Skipped large image (#{(event.payload[:size] / 1.kilobyte.to_f).round} KB): #{event.payload[:url]}" + log "Skipped large image (#{(event.payload[:size] / 1_000.0).round} KB): #{event.payload[:url]}" end def error(event)