Browse Source

Tweak image max size

Thibaut Courouble 8 năm trước cách đây
mục cha
commit
865efea85c

+ 3 - 7
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

+ 1 - 1
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)