vitals_image 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5399352c9f774e90f9a671459d582672c69c19b5640675e47a5c77536cb36826
4
- data.tar.gz: a05b961a9730225fd60f81c8d5467ab44a542abd8fa96d659891f805ee5a21b7
3
+ metadata.gz: 070dabcbfcfe58cf4ad78ed7509cf16963484fa160db4358ed2f400a1a7d7925
4
+ data.tar.gz: cecf4c19afeed8df374686752e3ee7300ecbe6ced03c15781a9f0caa6134418b
5
5
  SHA512:
6
- metadata.gz: 41a2aca3f4efb2178525af7566d24fe9825f858860a0b482c48ada2f49bc62edadb085986f165dc7d1d2875c5faf2e60114040c6318c6f52e469db620b32fb4d
7
- data.tar.gz: 1fe231165885de9b8c0876abfc466583f9fcb0da7c5ea2da73104e0d93348064c55e41fe9471decc0c077ac8392efcfe3f5c49b75db305c743752c7d78eeaa9a
6
+ metadata.gz: 424b3c5908a10ee87df1e8174b786f30166af7b8fc28c4473ca77775dafb77fb1cce5780568a1098efac6898eb4b97584857ea122555d68f81ead1f6b1cfbb5c
7
+ data.tar.gz: 9510a8c14a5363997d6729933b3356f0bf7145410498e850ccd27d346fbde54e6bdf013e4b6b97afd557279f26dae4e082c07ad188ecdbcdb3e1e3b984c1655e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5]
4
+
5
+ - Add `domains` config to allow limiting from which domains images will be analyzed
6
+ - User `after_commit` to enqueued analyze job
7
+
3
8
  ## [0.4.1] - 2021-07-22
4
9
 
5
10
  - Do not discard the specified `style` attribute
data/README.md CHANGED
@@ -134,6 +134,7 @@ The following configuration options are available. The defaults were chosen for
134
134
  | jpeg_optimization | see below | see below | Hash of options to pass to active storage when optimizing a JPEG. |
135
135
  | png_optimization | see below | see below | Hash of options to pass to active storage when optimizing a PNG. |
136
136
  | active_storage_route | `:inherited` | `:inherited` | Defines how urls of active storage images will be generated. If `inherited` it will use the same as active storage. Other valid options are `redirect`, `proxy` and `public`. Whatever is set here can be overriden in the helper. |
137
+ | domains | empty | - | Limits the domains that vitals image source can be created from |
137
138
 
138
139
  Minimagick
139
140
  ```ruby
@@ -164,8 +165,6 @@ These can be configured in your environment files, just like any other rails set
164
165
  ```
165
166
  Rails.application.configure do |config|
166
167
  config.vitals_image.image_library = :vips
167
- config.vitals_image.mobile_width = 410
168
- config.vitals_image.desktop_width = 1264
169
168
  config.vitals_image.lazy_loading = :lozad
170
169
  config.vitals_image.require_alt_attribute = true
171
170
  config.vitals_image.check_for_white_background = true
@@ -2,8 +2,8 @@
2
2
 
3
3
  module VitalsImage
4
4
  class Source < ActiveRecord::Base
5
- store :metadata, accessors: [ :analyzed, :width, :height ], coder: ActiveRecord::Coders::JSON, default: "{ analyzed: false }"
5
+ store :metadata, accessors: [ :identified, :analyzed, :width, :height ], coder: ActiveRecord::Coders::JSON
6
6
 
7
- after_create -> { AnalyzeJob.perform_later(self) }
7
+ after_create_commit -> { AnalyzeJob.perform_later(self) }
8
8
  end
9
9
  end
@@ -0,0 +1,6 @@
1
+ class AddFingerprintToVitalsImageSources < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :vitals_image_sources, :fingerprint, :string
4
+ add_index :vitals_image_sources, :fingerprint, unique: true
5
+ end
6
+ end
data/lib/vitals_image.rb CHANGED
@@ -14,8 +14,6 @@ module VitalsImage
14
14
  mattr_accessor :analyzers
15
15
  mattr_accessor :image_library
16
16
 
17
- mattr_accessor :mobile_width
18
- mattr_accessor :desktop_width
19
17
  mattr_accessor :resolution
20
18
  mattr_accessor :lazy_loading
21
19
  mattr_accessor :lazy_loading_placeholder
@@ -28,6 +26,7 @@ module VitalsImage
28
26
  mattr_accessor :jpeg_optimization
29
27
  mattr_accessor :png_optimization
30
28
  mattr_accessor :active_storage_route
29
+ mattr_accessor :domains
31
30
 
32
31
  mattr_accessor :skip_ssl_verification
33
32
  end
@@ -15,7 +15,7 @@ module VitalsImage
15
15
  source = @store.read(key)
16
16
 
17
17
  if source.blank?
18
- source = Source.find_or_create_by(key: key)
18
+ source = find_or_create_by(key)
19
19
  expires_in = source.analyzed ? nil : 1.minute
20
20
  @store.write(key, source, expires_in: expires_in)
21
21
  end
@@ -25,6 +25,16 @@ module VitalsImage
25
25
  end
26
26
 
27
27
  private
28
+ def find_or_create_by(key)
29
+ uri = URI.parse(key)
30
+
31
+ if VitalsImage.domains.present? && !VitalsImage.domains.include?(uri.host)
32
+ Source.new(key: key, metadata: { identified: false })
33
+ else
34
+ Source.find_or_create_by(key: key) { |source| source.identified = true }
35
+ end
36
+ end
37
+
28
38
  def with_retry
29
39
  yield
30
40
  rescue ActiveRecord::RecordNotUnique
@@ -29,6 +29,7 @@ module VitalsImage
29
29
  config.vitals_image = ActiveSupport::OrderedOptions.new
30
30
  config.vitals_image.optimizers = [VitalsImage::Optimizer::Blank, VitalsImage::Optimizer::Variable, VitalsImage::Optimizer::Invariable, VitalsImage::Optimizer::Url]
31
31
  config.vitals_image.analyzers = [VitalsImage::Analyzer::UrlAnalyzer]
32
+ config.vitals_image.domains = []
32
33
 
33
34
  config.eager_load_namespaces << VitalsImage
34
35
 
@@ -40,8 +41,6 @@ module VitalsImage
40
41
  VitalsImage.optimizers = app.config.vitals_image.optimizers || []
41
42
  VitalsImage.analyzers = app.config.vitals_image.analyzers || []
42
43
 
43
- VitalsImage.mobile_width = app.config.vitals_image.mobile_width || :original
44
- VitalsImage.desktop_width = app.config.vitals_image.desktop_width || :original
45
44
  VitalsImage.resolution = app.config.vitals_image.resolution || 2
46
45
  VitalsImage.lazy_loading = app.config.vitals_image.lazy_loading || :native
47
46
  VitalsImage.lazy_loading_placeholder = app.config.vitals_image.lazy_loading_placeholder || VitalsImage::Base::TINY_GIF
@@ -54,6 +53,7 @@ module VitalsImage
54
53
  VitalsImage.jpeg_conversion = app.config.vitals_image.jpeg_conversion
55
54
  VitalsImage.jpeg_optimization = app.config.vitals_image.jpeg_optimization
56
55
  VitalsImage.png_optimization = app.config.vitals_image.png_optimization
56
+ VitalsImage.domains = app.config.vitals_image.domains || []
57
57
 
58
58
  VitalsImage.skip_ssl_verification = app.config.vitals_image.skip_ssl_verification || false
59
59
  end
@@ -8,8 +8,8 @@ module VitalsImage
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 0
11
- MINOR = 4
12
- TINY = 1
11
+ MINOR = 5
12
+ TINY = 0
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -17,7 +17,7 @@ module VitalsImage
17
17
  end
18
18
 
19
19
  def style
20
- if !analyzed?
20
+ if !identified? || !analyzed?
21
21
  # Do nothing
22
22
  elsif !requested_height
23
23
  "height:auto;"
@@ -26,6 +26,10 @@ module VitalsImage
26
26
  end
27
27
  end
28
28
 
29
+ def identified?
30
+ metadata.identified
31
+ end
32
+
29
33
  def analyzed?
30
34
  metadata.analyzed
31
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitals_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Breno Gazzola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-22 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -243,6 +243,7 @@ files:
243
243
  - app/views/layouts/vitals_image/application.html.erb
244
244
  - config/routes.rb
245
245
  - db/migrate/20210502132155_create_vitals_image_sources.rb
246
+ - db/migrate/20210809171706_add_fingerprint_to_vitals_image_sources.rb
246
247
  - lib/tasks/vitals_image_tasks.rake
247
248
  - lib/vitals_image.rb
248
249
  - lib/vitals_image/analyzer.rb