mountable_image_server 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mountable_image_server/image_processor.rb +18 -5
- data/lib/mountable_image_server/version.rb +1 -1
- data/shell.nix +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffaf3db5f2b33f4e7e71c150f641da2dfd8c725e67c9349c802f6c4953eb309e
|
4
|
+
data.tar.gz: 680db514860ff0f6f6678be05e8e98705d1dff5462ca86361b464b4bf863d43b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e03f3c2f614b91fffc53903941277f44454a486d65178f1f3f59194d4867aaf765906564e52372203e43aaa0f1c48fb8ad7c00c58374883b16cbd6e9ae3fe8e
|
7
|
+
data.tar.gz: 34d25e94e1fea7bfed0238a3a3c5d5348205547cbf7a211378755b79ed422bf85d70e6f73a74e17bef90089367136c68047d8bc6bd5b560c0d7763dcee3f3ec9
|
@@ -15,14 +15,19 @@ module MountableImageServer
|
|
15
15
|
# `fm` - Format of image, use 'jpg', 'png', 'gif', ...
|
16
16
|
VALID_PARAMETERS = [:fit, :w, :h, :q, :darken, :fm]
|
17
17
|
|
18
|
+
PARAMETER_VALUE_PATTERNS = {
|
19
|
+
fit: /^(clip|crop)$/,
|
20
|
+
h: /^\d+$/,
|
21
|
+
w: /^\d+$/,
|
22
|
+
q: /^([0-9]|[1-9][0-9]|100)$/,
|
23
|
+
darken: /^([0-9]|[1-9][0-9]|100)$/,
|
24
|
+
fm: /^(jpg|png|gif)$/,
|
25
|
+
}
|
26
|
+
|
18
27
|
def initialize(path, parameters)
|
19
28
|
@path = path
|
20
29
|
@file_format = path.extname.downcase.scan(/[^\.]+/).last
|
21
|
-
@parameters = parameters
|
22
|
-
VALID_PARAMETERS.include?(key.to_sym) && value =~ /\S+/
|
23
|
-
end.map do |key, value|
|
24
|
-
[key.to_sym, value.strip.downcase]
|
25
|
-
end.to_h
|
30
|
+
@parameters = sanitize_parameters(parameters)
|
26
31
|
end
|
27
32
|
|
28
33
|
def run(&block)
|
@@ -70,6 +75,14 @@ module MountableImageServer
|
|
70
75
|
private
|
71
76
|
attr_reader :parameters, :path, :file_format
|
72
77
|
|
78
|
+
def sanitize_parameters(raw_parameters)
|
79
|
+
raw_parameters.select do |key, value|
|
80
|
+
VALID_PARAMETERS.include?(key.to_sym) && value =~ PARAMETER_VALUE_PATTERNS.fetch(key.to_sym)
|
81
|
+
end.map do |key, value|
|
82
|
+
[key.to_sym, value.strip.downcase]
|
83
|
+
end.to_h
|
84
|
+
end
|
85
|
+
|
73
86
|
def darken_operations
|
74
87
|
return [] unless parameters[:darken]
|
75
88
|
|
data/shell.nix
CHANGED