mini-smart-pkg 0.0.1

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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/carrierwave-3.1.3/README.md +1214 -0
  3. data/carrierwave-3.1.3/lib/carrierwave/compatibility/paperclip.rb +105 -0
  4. data/carrierwave-3.1.3/lib/carrierwave/downloader/base.rb +101 -0
  5. data/carrierwave-3.1.3/lib/carrierwave/downloader/remote_file.rb +68 -0
  6. data/carrierwave-3.1.3/lib/carrierwave/error.rb +8 -0
  7. data/carrierwave-3.1.3/lib/carrierwave/locale/en.yml +17 -0
  8. data/carrierwave-3.1.3/lib/carrierwave/mount.rb +446 -0
  9. data/carrierwave-3.1.3/lib/carrierwave/mounter.rb +257 -0
  10. data/carrierwave-3.1.3/lib/carrierwave/orm/activerecord.rb +68 -0
  11. data/carrierwave-3.1.3/lib/carrierwave/processing/mini_magick.rb +362 -0
  12. data/carrierwave-3.1.3/lib/carrierwave/processing/rmagick.rb +433 -0
  13. data/carrierwave-3.1.3/lib/carrierwave/processing/vips.rb +315 -0
  14. data/carrierwave-3.1.3/lib/carrierwave/processing.rb +3 -0
  15. data/carrierwave-3.1.3/lib/carrierwave/sanitized_file.rb +361 -0
  16. data/carrierwave-3.1.3/lib/carrierwave/storage/abstract.rb +43 -0
  17. data/carrierwave-3.1.3/lib/carrierwave/storage/file.rb +124 -0
  18. data/carrierwave-3.1.3/lib/carrierwave/storage/fog.rb +560 -0
  19. data/carrierwave-3.1.3/lib/carrierwave/storage.rb +3 -0
  20. data/carrierwave-3.1.3/lib/carrierwave/test/matchers.rb +398 -0
  21. data/carrierwave-3.1.3/lib/carrierwave/uploader/cache.rb +223 -0
  22. data/carrierwave-3.1.3/lib/carrierwave/uploader/callbacks.rb +33 -0
  23. data/carrierwave-3.1.3/lib/carrierwave/uploader/configuration.rb +229 -0
  24. data/carrierwave-3.1.3/lib/carrierwave/uploader/content_type_allowlist.rb +62 -0
  25. data/carrierwave-3.1.3/lib/carrierwave/uploader/content_type_denylist.rb +65 -0
  26. data/carrierwave-3.1.3/lib/carrierwave/uploader/default_url.rb +17 -0
  27. data/carrierwave-3.1.3/lib/carrierwave/uploader/dimension.rb +66 -0
  28. data/carrierwave-3.1.3/lib/carrierwave/uploader/download.rb +24 -0
  29. data/carrierwave-3.1.3/lib/carrierwave/uploader/extension_allowlist.rb +63 -0
  30. data/carrierwave-3.1.3/lib/carrierwave/uploader/extension_denylist.rb +64 -0
  31. data/carrierwave-3.1.3/lib/carrierwave/uploader/file_size.rb +43 -0
  32. data/carrierwave-3.1.3/lib/carrierwave/uploader/mountable.rb +44 -0
  33. data/carrierwave-3.1.3/lib/carrierwave/uploader/processing.rb +128 -0
  34. data/carrierwave-3.1.3/lib/carrierwave/uploader/proxy.rb +99 -0
  35. data/carrierwave-3.1.3/lib/carrierwave/uploader/remove.rb +21 -0
  36. data/carrierwave-3.1.3/lib/carrierwave/uploader/serialization.rb +28 -0
  37. data/carrierwave-3.1.3/lib/carrierwave/uploader/store.rb +168 -0
  38. data/carrierwave-3.1.3/lib/carrierwave/uploader/url.rb +44 -0
  39. data/carrierwave-3.1.3/lib/carrierwave/uploader/versions.rb +352 -0
  40. data/carrierwave-3.1.3/lib/carrierwave/uploader.rb +69 -0
  41. data/carrierwave-3.1.3/lib/carrierwave/utilities/file_name.rb +47 -0
  42. data/carrierwave-3.1.3/lib/carrierwave/utilities/uri.rb +26 -0
  43. data/carrierwave-3.1.3/lib/carrierwave/utilities.rb +7 -0
  44. data/carrierwave-3.1.3/lib/carrierwave/validations/active_model.rb +76 -0
  45. data/carrierwave-3.1.3/lib/carrierwave/version.rb +3 -0
  46. data/carrierwave-3.1.3/lib/carrierwave.rb +108 -0
  47. data/carrierwave-3.1.3/lib/generators/templates/uploader.rb.erb +56 -0
  48. data/carrierwave-3.1.3/lib/generators/uploader_generator.rb +7 -0
  49. data/mini-smart-pkg.gemspec +12 -0
  50. metadata +89 -0
@@ -0,0 +1,229 @@
1
+ require 'carrierwave/downloader/base'
2
+
3
+ module CarrierWave
4
+
5
+ module Uploader
6
+ module Configuration
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ class_attribute :_storage, :_cache_storage, :instance_writer => false
11
+
12
+ add_config :root
13
+ add_config :base_path
14
+ add_config :asset_host
15
+ add_config :permissions
16
+ add_config :directory_permissions
17
+ add_config :storage_engines
18
+ add_config :store_dir
19
+ add_config :cache_dir
20
+ add_config :enable_processing
21
+ add_config :ensure_multipart_form
22
+ add_config :delete_tmp_file_after_storage
23
+ add_config :move_to_cache
24
+ add_config :move_to_store
25
+ add_config :remove_previously_stored_files_after_update
26
+ add_config :downloader
27
+ add_config :force_extension
28
+
29
+ # fog
30
+ add_deprecated_config :fog_provider
31
+ add_config :fog_attributes
32
+ add_config :fog_credentials
33
+ add_config :fog_directory
34
+ add_config :fog_public
35
+ add_config :fog_authenticated_url_expiration
36
+ add_config :fog_use_ssl_for_aws
37
+ add_config :fog_aws_accelerate
38
+ add_config :fog_aws_fips
39
+
40
+ # Mounting
41
+ add_config :ignore_integrity_errors
42
+ add_config :ignore_processing_errors
43
+ add_config :ignore_download_errors
44
+ add_config :validate_integrity
45
+ add_config :validate_processing
46
+ add_config :validate_download
47
+ add_config :mount_on
48
+ add_config :cache_only
49
+ add_config :download_retry_count
50
+ add_config :download_retry_wait_time
51
+ add_config :skip_ssrf_protection
52
+
53
+ # set default values
54
+ reset_config
55
+ end
56
+
57
+ module ClassMethods
58
+
59
+ ##
60
+ # Sets the storage engine to be used when storing files with this uploader.
61
+ # Can be any class that implements a #store!(CarrierWave::SanitizedFile) and a #retrieve!
62
+ # method. See lib/carrierwave/storage/file.rb for an example. Storage engines should
63
+ # be added to CarrierWave::Uploader::Base.storage_engines so they can be referred
64
+ # to by a symbol, which should be more convenient
65
+ #
66
+ # If no argument is given, it will simply return the currently used storage engine.
67
+ #
68
+ # === Parameters
69
+ #
70
+ # [storage (Symbol, Class)] The storage engine to use for this uploader
71
+ #
72
+ # === Returns
73
+ #
74
+ # [Class] the storage engine to be used with this uploader
75
+ #
76
+ # === Examples
77
+ #
78
+ # storage :file
79
+ # storage CarrierWave::Storage::File
80
+ # storage MyCustomStorageEngine
81
+ #
82
+ def storage(storage = nil)
83
+ case storage
84
+ when Symbol
85
+ if (storage_engine = storage_engines[storage])
86
+ self._storage = eval storage_engine
87
+ else
88
+ raise CarrierWave::UnknownStorageError, "Unknown storage: #{storage}"
89
+ end
90
+ when nil
91
+ # noop
92
+ else
93
+ self._storage = storage
94
+ end
95
+ _storage
96
+ end
97
+ alias_method :storage=, :storage
98
+
99
+ ##
100
+ # Sets the cache storage engine to be used when storing cache files with this uploader.
101
+ # Same as .storage except for required methods being #cache!(CarrierWave::SanitizedFile),
102
+ # #retrieve_from_cache! and #delete_dir!.
103
+ #
104
+ # === Parameters
105
+ #
106
+ # [storage (Symbol, Class)] The cache storage engine to use for this uploader
107
+ #
108
+ # === Returns
109
+ #
110
+ # [Class] the cache storage engine to be used with this uploader
111
+ #
112
+ # === Examples
113
+ #
114
+ # cache_storage :file
115
+ # cache_storage CarrierWave::Storage::File
116
+ # cache_storage MyCustomStorageEngine
117
+ #
118
+ def cache_storage(storage = false)
119
+ unless storage == false
120
+ self._cache_storage = storage.is_a?(Symbol) ? eval(storage_engines[storage]) : storage
121
+ end
122
+ _cache_storage
123
+ end
124
+ alias_method :cache_storage=, :cache_storage
125
+
126
+ def add_config(name)
127
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
128
+ @#{name} = nil
129
+
130
+ def self.#{name}(value=nil)
131
+ @#{name} = value unless value.nil?
132
+ return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
133
+ name = superclass.#{name}
134
+ return nil if name.nil? && !instance_variable_defined?(:@#{name})
135
+ @#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
136
+ end
137
+
138
+ def self.#{name}=(value)
139
+ @#{name} = value
140
+ end
141
+
142
+ def #{name}=(value)
143
+ @#{name} = value
144
+ end
145
+
146
+ def #{name}
147
+ value = @#{name} if instance_variable_defined?(:@#{name})
148
+ value = self.class.#{name} unless instance_variable_defined?(:@#{name})
149
+ if value.instance_of?(Proc)
150
+ value.arity >= 1 ? value.call(self) : value.call
151
+ else
152
+ value
153
+ end
154
+ end
155
+ RUBY
156
+ end
157
+
158
+ def add_deprecated_config(name)
159
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
160
+ def self.#{name}(value=nil)
161
+ CarrierWave.deprecator.warn "##{name} is deprecated and has no effect"
162
+ end
163
+
164
+ def self.#{name}=(value)
165
+ CarrierWave.deprecator.warn "##{name} is deprecated and has no effect"
166
+ end
167
+
168
+ def #{name}=(value)
169
+ CarrierWave.deprecator.warn "##{name} is deprecated and has no effect"
170
+ end
171
+
172
+ def #{name}
173
+ CarrierWave.deprecator.warn "##{name} is deprecated and has no effect"
174
+ end
175
+ RUBY
176
+ end
177
+
178
+ def configure
179
+ yield self
180
+ end
181
+
182
+ ##
183
+ # sets configuration back to default
184
+ #
185
+ def reset_config
186
+ configure do |config|
187
+ config.permissions = 0o644
188
+ config.directory_permissions = 0o755
189
+ config.storage_engines = {
190
+ :file => "CarrierWave::Storage::File",
191
+ :fog => "CarrierWave::Storage::Fog"
192
+ }
193
+ config.storage = :file
194
+ config.cache_storage = nil
195
+ config.fog_attributes = {}
196
+ config.fog_credentials = {}
197
+ config.fog_public = true
198
+ config.fog_authenticated_url_expiration = 600
199
+ config.fog_use_ssl_for_aws = true
200
+ config.fog_aws_accelerate = false
201
+ config.fog_aws_fips = false
202
+ config.store_dir = 'uploads'
203
+ config.cache_dir = 'uploads/tmp'
204
+ config.delete_tmp_file_after_storage = true
205
+ config.move_to_cache = false
206
+ config.move_to_store = false
207
+ config.remove_previously_stored_files_after_update = true
208
+ config.downloader = CarrierWave::Downloader::Base
209
+ config.force_extension = false
210
+ config.ignore_integrity_errors = true
211
+ config.ignore_processing_errors = true
212
+ config.ignore_download_errors = true
213
+ config.validate_integrity = true
214
+ config.validate_processing = true
215
+ config.validate_download = true
216
+ config.root = lambda { CarrierWave.root }
217
+ config.base_path = CarrierWave.base_path
218
+ config.enable_processing = true
219
+ config.ensure_multipart_form = true
220
+ config.download_retry_count = 0
221
+ config.download_retry_wait_time = 5
222
+ config.skip_ssrf_protection = false
223
+ end
224
+ end
225
+ end
226
+
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,62 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module ContentTypeAllowlist
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_content_type_allowlist!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide an allowlist of files content types
12
+ # which are allowed to be uploaded.
13
+ # Not only strings but Regexp are allowed as well.
14
+ #
15
+ # === Returns
16
+ #
17
+ # [NilClass, String, Regexp, Array[String, Regexp]] an allowlist of content types which are allowed to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def content_type_allowlist
22
+ # %w(text/json application/json)
23
+ # end
24
+ #
25
+ # Basically the same, but using a Regexp:
26
+ #
27
+ # def content_type_allowlist
28
+ # [/(text|application)\/json/]
29
+ # end
30
+ #
31
+ def content_type_allowlist
32
+ end
33
+
34
+ private
35
+
36
+ def check_content_type_allowlist!(new_file)
37
+ allowlist = content_type_allowlist
38
+ if !allowlist && respond_to?(:content_type_whitelist) && content_type_whitelist
39
+ CarrierWave.deprecator.warn "#content_type_whitelist is deprecated, use #content_type_allowlist instead." unless instance_variable_defined?(:@content_type_whitelist_warned)
40
+ @content_type_whitelist_warned = true
41
+ allowlist = content_type_whitelist
42
+ end
43
+
44
+ return unless allowlist
45
+
46
+ content_type = new_file.content_type
47
+ if !allowlisted_content_type?(allowlist, content_type)
48
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_allowlist_error", content_type: content_type,
49
+ allowed_types: Array(allowlist).join(", "), default: :"errors.messages.content_type_whitelist_error")
50
+ end
51
+ end
52
+
53
+ def allowlisted_content_type?(allowlist, content_type)
54
+ Array(allowlist).any? do |item|
55
+ item = Regexp.quote(item) if item.class != Regexp
56
+ content_type =~ /\A#{item}/
57
+ end
58
+ end
59
+
60
+ end # ContentTypeAllowlist
61
+ end # Uploader
62
+ end # CarrierWave
@@ -0,0 +1,65 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module ContentTypeDenylist
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_content_type_denylist!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide a denylist of files content types
12
+ # which are not allowed to be uploaded.
13
+ # Not only strings but Regexp are allowed as well.
14
+ #
15
+ # === Returns
16
+ #
17
+ # [NilClass, String, Regexp, Array[String, Regexp]] a denylist of content types which are not allowed to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def content_type_denylist
22
+ # %w(text/json application/json)
23
+ # end
24
+ #
25
+ # Basically the same, but using a Regexp:
26
+ #
27
+ # def content_type_denylist
28
+ # [/(text|application)\/json/]
29
+ # end
30
+ #
31
+ def content_type_denylist
32
+ end
33
+
34
+ private
35
+
36
+ def check_content_type_denylist!(new_file)
37
+ denylist = content_type_denylist
38
+ if !denylist && respond_to?(:content_type_blacklist) && content_type_blacklist
39
+ CarrierWave.deprecator.warn "#content_type_blacklist is deprecated, use #content_type_denylist instead." unless instance_variable_defined?(:@content_type_blacklist_warned)
40
+ @content_type_blacklist_warned = true
41
+ denylist = content_type_blacklist
42
+ end
43
+
44
+ return unless denylist
45
+
46
+ CarrierWave.deprecator.warn "Use of #content_type_denylist is deprecated for the security reason, use #content_type_allowlist instead to explicitly state what are safe to accept" unless instance_variable_defined?(:@content_type_denylist_warned)
47
+ @content_type_denylist_warned = true
48
+
49
+ content_type = new_file.content_type
50
+ if denylisted_content_type?(denylist, content_type)
51
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_denylist_error",
52
+ content_type: content_type, default: :"errors.messages.content_type_blacklist_error")
53
+ end
54
+ end
55
+
56
+ def denylisted_content_type?(denylist, content_type)
57
+ Array(denylist).any? do |item|
58
+ item = Regexp.quote(item) if item.class != Regexp
59
+ content_type =~ /#{item}/
60
+ end
61
+ end
62
+
63
+ end # ContentTypeDenylist
64
+ end # Uploader
65
+ end # CarrierWave
@@ -0,0 +1,17 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module DefaultUrl
4
+
5
+ def url(*args)
6
+ super || default_url(*args)
7
+ end
8
+
9
+ ##
10
+ # Override this method in your uploader to provide a default url
11
+ # in case no file has been cached/stored yet.
12
+ #
13
+ def default_url(*args); end
14
+
15
+ end # DefaultPath
16
+ end # Uploader
17
+ end # CarrierWave
@@ -0,0 +1,66 @@
1
+ require 'active_support'
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Dimension
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before :cache, :check_dimensions!
10
+ end
11
+
12
+ ##
13
+ # Override this method in your uploader to provide a Range of width which
14
+ # are allowed to be uploaded.
15
+ # === Returns
16
+ #
17
+ # [NilClass, Range] a width range which are permitted to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def width_range
22
+ # 1000..2000
23
+ # end
24
+ #
25
+ def width_range; end
26
+
27
+ ##
28
+ # Override this method in your uploader to provide a Range of height which
29
+ # are allowed to be uploaded.
30
+ # === Returns
31
+ #
32
+ # [NilClass, Range] a height range which are permitted to be uploaded
33
+ #
34
+ # === Examples
35
+ #
36
+ # def height_range
37
+ # 1000..
38
+ # end
39
+ #
40
+ def height_range; end
41
+
42
+ private
43
+
44
+ def check_dimensions!(new_file)
45
+ # NOTE: Skip the check for resized images
46
+ return if version_name.present?
47
+ return unless width_range || height_range
48
+
49
+ unless respond_to?(:width) || respond_to?(:height)
50
+ raise 'You need to include one of CarrierWave::MiniMagick, CarrierWave::RMagick, or CarrierWave::Vips to perform image dimension validation'
51
+ end
52
+
53
+ if width_range&.begin && width < width_range.begin
54
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_width_error", :min_width => ActiveSupport::NumberHelper.number_to_delimited(width_range.begin))
55
+ elsif width_range&.end && width > width_range.end
56
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_width_error", :max_width => ActiveSupport::NumberHelper.number_to_delimited(width_range.end))
57
+ elsif height_range&.begin && height < height_range.begin
58
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_height_error", :min_height => ActiveSupport::NumberHelper.number_to_delimited(height_range.begin))
59
+ elsif height_range&.end && height > height_range.end
60
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_height_error", :max_height => ActiveSupport::NumberHelper.number_to_delimited(height_range.end))
61
+ end
62
+ end
63
+
64
+ end # Dimension
65
+ end # Uploader
66
+ end # CarrierWave
@@ -0,0 +1,24 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module Download
4
+ extend ActiveSupport::Concern
5
+
6
+ include CarrierWave::Uploader::Callbacks
7
+ include CarrierWave::Uploader::Configuration
8
+ include CarrierWave::Uploader::Cache
9
+
10
+ ##
11
+ # Caches the file by downloading it from the given URL, using downloader.
12
+ #
13
+ # === Parameters
14
+ #
15
+ # [url (String)] The URL where the remote file is stored
16
+ # [remote_headers (Hash)] Request headers
17
+ #
18
+ def download!(uri, remote_headers = {})
19
+ file = downloader.new(self).download(uri, remote_headers)
20
+ cache!(file)
21
+ end
22
+ end # Download
23
+ end # Uploader
24
+ end # CarrierWave
@@ -0,0 +1,63 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module ExtensionAllowlist
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_extension_allowlist!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide an allowlist of extensions which
12
+ # are allowed to be uploaded. Compares the file's extension case insensitive.
13
+ # Furthermore, not only strings but Regexp are allowed as well.
14
+ #
15
+ # When using a Regexp in the allowlist, `\A` and `\z` are automatically added to
16
+ # the Regexp expression, also case insensitive.
17
+ #
18
+ # === Returns
19
+ #
20
+ # [NilClass, String, Regexp, Array[String, Regexp]] an allowlist of extensions which are allowed to be uploaded
21
+ #
22
+ # === Examples
23
+ #
24
+ # def extension_allowlist
25
+ # %w(jpg jpeg gif png)
26
+ # end
27
+ #
28
+ # Basically the same, but using a Regexp:
29
+ #
30
+ # def extension_allowlist
31
+ # [/jpe?g/, 'gif', 'png']
32
+ # end
33
+ #
34
+ def extension_allowlist
35
+ end
36
+
37
+ private
38
+
39
+ def check_extension_allowlist!(new_file)
40
+ allowlist = extension_allowlist
41
+ if !allowlist && respond_to?(:extension_whitelist) && extension_whitelist
42
+ CarrierWave.deprecator.warn "#extension_whitelist is deprecated, use #extension_allowlist instead." unless instance_variable_defined?(:@extension_whitelist_warned)
43
+ @extension_whitelist_warned = true
44
+ allowlist = extension_whitelist
45
+ end
46
+
47
+ return unless allowlist
48
+
49
+ extension = new_file.extension.to_s
50
+ if !allowlisted_extension?(allowlist, extension)
51
+ # Look for whitelist first, then fallback to allowlist
52
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_allowlist_error", extension: new_file.extension.inspect,
53
+ allowed_types: Array(allowlist).join(", "), default: :"errors.messages.extension_whitelist_error")
54
+ end
55
+ end
56
+
57
+ def allowlisted_extension?(allowlist, extension)
58
+ downcase_extension = extension.downcase
59
+ Array(allowlist).any? { |item| downcase_extension =~ /\A#{item}\z/i }
60
+ end
61
+ end # ExtensionAllowlist
62
+ end # Uploader
63
+ end # CarrierWave
@@ -0,0 +1,64 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module ExtensionDenylist
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_extension_denylist!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide a denylist of extensions which
12
+ # are prohibited to be uploaded. Compares the file's extension case insensitive.
13
+ # Furthermore, not only strings but Regexp are allowed as well.
14
+ #
15
+ # When using a Regexp in the denylist, `\A` and `\z` are automatically added to
16
+ # the Regexp expression, also case insensitive.
17
+ #
18
+ # === Returns
19
+
20
+ # [NilClass, String, Regexp, Array[String, Regexp]] a deny list of extensions which are prohibited to be uploaded
21
+ #
22
+ # === Examples
23
+ #
24
+ # def extension_denylist
25
+ # %w(swf tiff)
26
+ # end
27
+ #
28
+ # Basically the same, but using a Regexp:
29
+ #
30
+ # def extension_denylist
31
+ # [/swf/, 'tiff']
32
+ # end
33
+ #
34
+ def extension_denylist
35
+ end
36
+
37
+ private
38
+
39
+ def check_extension_denylist!(new_file)
40
+ denylist = extension_denylist
41
+ if !denylist && respond_to?(:extension_blacklist) && extension_blacklist
42
+ CarrierWave.deprecator.warn "#extension_blacklist is deprecated, use #extension_denylist instead." unless instance_variable_defined?(:@extension_blacklist_warned)
43
+ @extension_blacklist_warned = true
44
+ denylist = extension_blacklist
45
+ end
46
+
47
+ return unless denylist
48
+
49
+ CarrierWave.deprecator.warn "Use of #extension_denylist is deprecated for the security reason, use #extension_allowlist instead to explicitly state what are safe to accept" unless instance_variable_defined?(:@extension_denylist_warned)
50
+ @extension_denylist_warned = true
51
+
52
+ extension = new_file.extension.to_s
53
+ if denylisted_extension?(denylist, extension)
54
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_denylist_error", extension: new_file.extension.inspect,
55
+ prohibited_types: Array(extension_denylist).join(", "), default: :"errors.messages.extension_blacklist_error")
56
+ end
57
+ end
58
+
59
+ def denylisted_extension?(denylist, extension)
60
+ Array(denylist).any? { |item| extension =~ /\A#{item}\z/i }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,43 @@
1
+ require 'active_support'
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module FileSize
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before :cache, :check_size!
10
+ end
11
+
12
+ ##
13
+ # Override this method in your uploader to provide a Range of Size which
14
+ # are allowed to be uploaded.
15
+ # === Returns
16
+ #
17
+ # [NilClass, Range] a size range (in bytes) which are permitted to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def size_range
22
+ # 3256...5748
23
+ # end
24
+ #
25
+ def size_range; end
26
+
27
+ private
28
+
29
+ def check_size!(new_file)
30
+ size = new_file.size
31
+ expected_size_range = size_range
32
+ if expected_size_range.is_a?(::Range)
33
+ if size < expected_size_range.min
34
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_size_error", :min_size => ActiveSupport::NumberHelper.number_to_human_size(expected_size_range.min))
35
+ elsif size > expected_size_range.max
36
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_size_error", :max_size => ActiveSupport::NumberHelper.number_to_human_size(expected_size_range.max))
37
+ end
38
+ end
39
+ end
40
+
41
+ end # FileSize
42
+ end # Uploader
43
+ end # CarrierWave
@@ -0,0 +1,44 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module Mountable
4
+
5
+ attr_reader :model, :mounted_as
6
+
7
+ ##
8
+ # If a model is given as the first parameter, it will be stored in the
9
+ # uploader, and available through +#model+. Likewise, mounted_as stores
10
+ # the name of the column where this instance of the uploader is mounted.
11
+ # These values can then be used inside your uploader.
12
+ #
13
+ # If you do not wish to mount your uploaders with the ORM extensions in
14
+ # -more then you can override this method inside your uploader. Just be
15
+ # sure to call +super+
16
+ #
17
+ # === Parameters
18
+ #
19
+ # [model (Object)] Any kind of model object
20
+ # [mounted_as (Symbol)] The name of the column where this uploader is mounted
21
+ #
22
+ # === Examples
23
+ #
24
+ # class MyUploader < CarrierWave::Uploader::Base
25
+ #
26
+ # def store_dir
27
+ # File.join('public', 'files', mounted_as, model.permalink)
28
+ # end
29
+ # end
30
+ #
31
+ def initialize(model=nil, mounted_as=nil)
32
+ @model = model
33
+ @mounted_as = mounted_as
34
+ end
35
+
36
+ ##
37
+ # Returns array index of given uploader within currently mounted uploaders
38
+ #
39
+ def index
40
+ model.__send__(:_mounter, mounted_as).uploaders.index(self)
41
+ end
42
+ end # Mountable
43
+ end # Uploader
44
+ end # CarrierWave