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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63c63a9eab25e840d81dffc313e19a280367674550cb7e985b6d5a5c1947e060
4
- data.tar.gz: ff7b2820a0a88aebd46245e0089271c527ae7823ca274ad74625ae5db88ad3fd
3
+ metadata.gz: ffaf3db5f2b33f4e7e71c150f641da2dfd8c725e67c9349c802f6c4953eb309e
4
+ data.tar.gz: 680db514860ff0f6f6678be05e8e98705d1dff5462ca86361b464b4bf863d43b
5
5
  SHA512:
6
- metadata.gz: 8c7d3c782dd5f6d86781be932683afa8be1a58ff83f9ff9c9d54865c74853f143f905c4390d6ae20e797401b1aecf9d42cbadaf85689dc08942abcd4c3e620dc
7
- data.tar.gz: 4acd2cd370f9e7f085fd19d9caa87dfcea39b5443ba89d05f641ccbb77b923c28366dc728bbe6d1359ad8b20b9e29de029df3bb2179360523061fb09d46463a5
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.select do |key, value|
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
 
@@ -1,3 +1,3 @@
1
1
  module MountableImageServer
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/shell.nix CHANGED
@@ -17,6 +17,7 @@ pkgs.mkShell {
17
17
  phantomjs
18
18
  rubyPackages_2_5.nokogiri
19
19
  libiconv
20
+ imagemagick
20
21
  ];
21
22
 
22
23
  shellHook = ''
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mountable_image_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Strauß