active_storage_validations 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9b366848f85ac520038a9efe0bee0514338f4d28b8f292ef87ad06d1ee0da28
|
4
|
+
data.tar.gz: 651195be6d5d23bf20c4600656e799005e3e1fc118ac21cc5fe023b24f43ae73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6231454bce1c4b09bf4dba3a83238f09b3fa0593c0c04146342ac6dd035048f890edcb594d24747f9d5e55d5ef86a35eba7fa93b109f101906b0f5b4f373c06
|
7
|
+
data.tar.gz: 6a5a9a0abd3f7abbddd92d8f1e5601859bbcc06e17f049046e5c9e2744760aa4fd7fa77462c22fb8d076cc4aef801e9b814a6b8663edb08e9c32a497ec041908
|
data/README.md
CHANGED
@@ -375,6 +375,9 @@ You are welcome to contribute.
|
|
375
375
|
- https://github.com/luiseugenio
|
376
376
|
- https://github.com/equivalent
|
377
377
|
- https://github.com/NARKOZ
|
378
|
+
- https://github.com/stephensolis
|
379
|
+
- https://github.com/kwent
|
380
|
+
= https://github.com/Animesh-Ghosh
|
378
381
|
|
379
382
|
## License
|
380
383
|
|
@@ -89,29 +89,32 @@ module ActiveStorageValidations
|
|
89
89
|
|
90
90
|
# Validation based on checks :width and :height.
|
91
91
|
else
|
92
|
+
width_or_height_invalid = false
|
92
93
|
[:width, :height].each do |length|
|
93
94
|
next unless options[length]
|
94
95
|
if options[length].is_a?(Hash)
|
95
96
|
if options[length][:in] && (file_metadata[length] < options[length][:min] || file_metadata[length] > options[length][:max])
|
96
97
|
add_error(record, attribute, options[:message].presence || :"dimension_#{length}_inclusion", min: options[length][:min], max: options[length][:max])
|
97
|
-
|
98
|
+
width_or_height_invalid = true
|
98
99
|
else
|
99
100
|
if options[length][:min] && file_metadata[length] < options[length][:min]
|
100
101
|
add_error(record, attribute, options[:message].presence || :"dimension_#{length}_greater_than_or_equal_to", length: options[length][:min])
|
101
|
-
|
102
|
+
width_or_height_invalid = true
|
102
103
|
end
|
103
104
|
if options[length][:max] && file_metadata[length] > options[length][:max]
|
104
105
|
add_error(record, attribute, options[:message].presence || :"dimension_#{length}_less_than_or_equal_to", length: options[length][:max])
|
105
|
-
|
106
|
+
width_or_height_invalid = true
|
106
107
|
end
|
107
108
|
end
|
108
109
|
else
|
109
110
|
if file_metadata[length] != options[length]
|
110
111
|
add_error(record, attribute, options[:message].presence || :"dimension_#{length}_equal_to", length: options[length])
|
111
|
-
|
112
|
+
width_or_height_invalid = true
|
112
113
|
end
|
113
114
|
end
|
114
115
|
end
|
116
|
+
|
117
|
+
return false if width_or_height_invalid
|
115
118
|
end
|
116
119
|
|
117
120
|
true # valid file
|
@@ -10,6 +10,14 @@ module ActiveStorageValidations
|
|
10
10
|
def image_processor
|
11
11
|
Rails.application.config.active_storage.variant_processor
|
12
12
|
end
|
13
|
+
|
14
|
+
def exception_class
|
15
|
+
if image_processor == :vips && defined?(Vips)
|
16
|
+
Vips::Error
|
17
|
+
elsif defined?(MiniMagick)
|
18
|
+
MiniMagick::Error
|
19
|
+
end
|
20
|
+
end
|
13
21
|
|
14
22
|
def require_image_processor
|
15
23
|
if image_processor == :vips
|
@@ -55,15 +63,15 @@ module ActiveStorageValidations
|
|
55
63
|
tempfile.flush
|
56
64
|
tempfile.rewind
|
57
65
|
|
58
|
-
image = if image_processor == :vips && Vips::get_suffixes.include?(File.extname(tempfile.path))
|
66
|
+
image = if image_processor == :vips && defined?(Vips) && Vips::get_suffixes.include?(File.extname(tempfile.path).downcase)
|
59
67
|
Vips::Image.new_from_file(tempfile.path)
|
60
|
-
|
68
|
+
elsif defined?(MiniMagick)
|
61
69
|
MiniMagick::Image.new(tempfile.path)
|
62
70
|
end
|
63
71
|
else
|
64
|
-
image = if image_processor == :vips && Vips::get_suffixes.include?(File.extname(read_file_path))
|
72
|
+
image = if image_processor == :vips && defined?(Vips) && Vips::get_suffixes.include?(File.extname(read_file_path).downcase)
|
65
73
|
Vips::Image.new_from_file(read_file_path)
|
66
|
-
|
74
|
+
elsif defined?(MiniMagick)
|
67
75
|
MiniMagick::Image.new(read_file_path)
|
68
76
|
end
|
69
77
|
end
|
@@ -77,30 +85,27 @@ module ActiveStorageValidations
|
|
77
85
|
rescue LoadError, NameError
|
78
86
|
logger.info "Skipping image analysis because the mini_magick or ruby-vips gem isn't installed"
|
79
87
|
{}
|
80
|
-
rescue
|
81
|
-
logger.error "Skipping image analysis due to an
|
82
|
-
{}
|
83
|
-
rescue Vips::Error => error
|
84
|
-
logger.error "Skipping image analysis due to a Vips error: #{error.message}"
|
88
|
+
rescue exception_class => error
|
89
|
+
logger.error "Skipping image analysis due to an #{exception_class.name.split('::').map(&:downcase).join(' ').capitalize} error: #{error.message}"
|
85
90
|
{}
|
86
91
|
ensure
|
87
92
|
image = nil
|
88
93
|
end
|
89
94
|
|
90
95
|
def valid_image?(image)
|
91
|
-
image_processor == :vips ? image.avg : image.valid?
|
92
|
-
rescue
|
96
|
+
image_processor == :vips && image.is_a?(Vips::Image) ? image.avg : image.valid?
|
97
|
+
rescue exception_class
|
93
98
|
false
|
94
99
|
end
|
95
100
|
|
96
101
|
def rotated_image?(image)
|
97
|
-
if image_processor == :vips
|
102
|
+
if image_processor == :vips && image.is_a?(Vips::Image)
|
98
103
|
image.get('exif-ifd0-Orientation').include?('Right-top') ||
|
99
104
|
image.get('exif-ifd0-Orientation').include?('Left-bottom')
|
100
105
|
else
|
101
106
|
%w[ RightTop LeftBottom ].include?(image["%[orientation]"])
|
102
107
|
end
|
103
|
-
rescue
|
108
|
+
rescue exception_class # field "exif-ifd0-Orientation" not found
|
104
109
|
false
|
105
110
|
end
|
106
111
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|