carrierwave 0.11.2 → 3.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +452 -178
- data/lib/carrierwave/compatibility/paperclip.rb +4 -4
- data/lib/carrierwave/downloader/base.rb +101 -0
- data/lib/carrierwave/downloader/remote_file.rb +68 -0
- data/lib/carrierwave/error.rb +1 -0
- data/lib/carrierwave/locale/en.yml +11 -5
- data/lib/carrierwave/mount.rb +217 -182
- data/lib/carrierwave/mounter.rb +255 -0
- data/lib/carrierwave/orm/activerecord.rb +29 -35
- data/lib/carrierwave/processing/mini_magick.rb +140 -84
- data/lib/carrierwave/processing/rmagick.rb +72 -21
- data/lib/carrierwave/processing/vips.rb +284 -0
- data/lib/carrierwave/processing.rb +1 -1
- data/lib/carrierwave/sanitized_file.rb +83 -84
- data/lib/carrierwave/storage/abstract.rb +16 -3
- data/lib/carrierwave/storage/file.rb +71 -3
- data/lib/carrierwave/storage/fog.rb +215 -57
- data/lib/carrierwave/storage.rb +1 -9
- data/lib/carrierwave/test/matchers.rb +88 -19
- data/lib/carrierwave/uploader/cache.rb +75 -45
- data/lib/carrierwave/uploader/callbacks.rb +1 -3
- data/lib/carrierwave/uploader/configuration.rb +80 -16
- data/lib/carrierwave/uploader/content_type_allowlist.rb +62 -0
- data/lib/carrierwave/uploader/content_type_denylist.rb +62 -0
- data/lib/carrierwave/uploader/default_url.rb +3 -5
- data/lib/carrierwave/uploader/dimension.rb +66 -0
- data/lib/carrierwave/uploader/download.rb +4 -74
- data/lib/carrierwave/uploader/extension_allowlist.rb +63 -0
- data/lib/carrierwave/uploader/extension_denylist.rb +64 -0
- data/lib/carrierwave/uploader/file_size.rb +43 -0
- data/lib/carrierwave/uploader/mountable.rb +13 -8
- data/lib/carrierwave/uploader/processing.rb +48 -13
- data/lib/carrierwave/uploader/proxy.rb +20 -9
- data/lib/carrierwave/uploader/remove.rb +0 -2
- data/lib/carrierwave/uploader/serialization.rb +2 -4
- data/lib/carrierwave/uploader/store.rb +59 -28
- data/lib/carrierwave/uploader/url.rb +8 -7
- data/lib/carrierwave/uploader/versions.rb +171 -123
- data/lib/carrierwave/uploader.rb +12 -10
- data/lib/carrierwave/utilities/file_name.rb +47 -0
- data/lib/carrierwave/utilities/uri.rb +14 -12
- data/lib/carrierwave/utilities.rb +1 -3
- data/lib/carrierwave/validations/active_model.rb +7 -11
- data/lib/carrierwave/version.rb +1 -1
- data/lib/carrierwave.rb +39 -21
- data/lib/generators/templates/{uploader.rb → uploader.rb.erb} +6 -10
- data/lib/generators/uploader_generator.rb +3 -3
- metadata +135 -83
- data/lib/carrierwave/locale/cs.yml +0 -11
- data/lib/carrierwave/locale/de.yml +0 -11
- data/lib/carrierwave/locale/el.yml +0 -11
- data/lib/carrierwave/locale/es.yml +0 -11
- data/lib/carrierwave/locale/fr.yml +0 -11
- data/lib/carrierwave/locale/ja.yml +0 -11
- data/lib/carrierwave/locale/nb.yml +0 -11
- data/lib/carrierwave/locale/nl.yml +0 -11
- data/lib/carrierwave/locale/pl.yml +0 -11
- data/lib/carrierwave/locale/pt-BR.yml +0 -11
- data/lib/carrierwave/locale/pt-PT.yml +0 -11
- data/lib/carrierwave/locale/ru.yml +0 -11
- data/lib/carrierwave/locale/sk.yml +0 -11
- data/lib/carrierwave/locale/tr.yml +0 -11
- data/lib/carrierwave/processing/mime_types.rb +0 -74
- data/lib/carrierwave/uploader/content_type_blacklist.rb +0 -48
- data/lib/carrierwave/uploader/content_type_whitelist.rb +0 -48
- data/lib/carrierwave/uploader/extension_blacklist.rb +0 -47
- data/lib/carrierwave/uploader/extension_whitelist.rb +0 -49
- data/lib/carrierwave/utilities/deprecation.rb +0 -18
@@ -1,74 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module CarrierWave
|
4
|
-
|
5
|
-
##
|
6
|
-
# This module simplifies the use of the mime-types gem to intelligently
|
7
|
-
# guess and set the content-type of a file. If you want to use this, you'll
|
8
|
-
# need to require this file:
|
9
|
-
#
|
10
|
-
# require 'carrierwave/processing/mime_types'
|
11
|
-
#
|
12
|
-
# And then include it in your uploader:
|
13
|
-
#
|
14
|
-
# class MyUploader < CarrierWave::Uploader::Base
|
15
|
-
# include CarrierWave::MimeTypes
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# You can now use the provided helper:
|
19
|
-
#
|
20
|
-
# class MyUploader < CarrierWave::Uploader::Base
|
21
|
-
# include CarrierWave::MimeTypes
|
22
|
-
#
|
23
|
-
# process :set_content_type
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
module MimeTypes
|
27
|
-
extend ActiveSupport::Concern
|
28
|
-
|
29
|
-
included do
|
30
|
-
CarrierWave::Utilities::Deprecation.new "0.11.0", "CarrierWave::MimeTypes is deprecated and will be removed in the future, get the content_type from the SanitizedFile object directly."
|
31
|
-
begin
|
32
|
-
require "mime/types"
|
33
|
-
rescue LoadError => e
|
34
|
-
e.message << " (You may need to install the mime-types gem)"
|
35
|
-
raise e
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module ClassMethods
|
40
|
-
def set_content_type(override=false)
|
41
|
-
process :set_content_type => override
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
GENERIC_CONTENT_TYPES = %w[application/octet-stream binary/octet-stream]
|
46
|
-
|
47
|
-
def generic_content_type?
|
48
|
-
GENERIC_CONTENT_TYPES.include? file.content_type
|
49
|
-
end
|
50
|
-
|
51
|
-
##
|
52
|
-
# Changes the file content_type using the mime-types gem
|
53
|
-
#
|
54
|
-
# === Parameters
|
55
|
-
#
|
56
|
-
# [override (Boolean)] whether or not to override the file's content_type
|
57
|
-
# if it is already set and not a generic content-type,
|
58
|
-
# false by default
|
59
|
-
#
|
60
|
-
def set_content_type(override=false)
|
61
|
-
if override || file.content_type.blank? || generic_content_type?
|
62
|
-
new_content_type = ::MIME::Types.type_for(file.original_filename).first.to_s
|
63
|
-
if file.respond_to?(:content_type=)
|
64
|
-
file.content_type = new_content_type
|
65
|
-
else
|
66
|
-
file.instance_variable_set(:@content_type, new_content_type)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
rescue ::MIME::InvalidContentType => e
|
70
|
-
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.mime_types_processing_error", :e => e)
|
71
|
-
end
|
72
|
-
|
73
|
-
end # MimeTypes
|
74
|
-
end # CarrierWave
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module CarrierWave
|
2
|
-
module Uploader
|
3
|
-
module ContentTypeBlacklist
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
before :cache, :check_content_type_blacklist!
|
8
|
-
end
|
9
|
-
|
10
|
-
##
|
11
|
-
# Override this method in your uploader to provide a blacklist 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 blacklist of content types which are not allowed to be uploaded
|
18
|
-
#
|
19
|
-
# === Examples
|
20
|
-
#
|
21
|
-
# def content_type_blacklist
|
22
|
-
# %w(text/json application/json)
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# Basically the same, but using a Regexp:
|
26
|
-
#
|
27
|
-
# def content_type_blacklist
|
28
|
-
# [/(text|application)\/json/]
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
def content_type_blacklist; end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def check_content_type_blacklist!(new_file)
|
36
|
-
content_type = new_file.content_type
|
37
|
-
if content_type_blacklist && blacklisted_content_type?(content_type)
|
38
|
-
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_blacklist_error", content_type: content_type)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def blacklisted_content_type?(content_type)
|
43
|
-
Array(content_type_blacklist).any? { |item| content_type =~ /#{item}/ }
|
44
|
-
end
|
45
|
-
|
46
|
-
end # ContentTypeBlacklist
|
47
|
-
end # Uploader
|
48
|
-
end # CarrierWave
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module CarrierWave
|
2
|
-
module Uploader
|
3
|
-
module ContentTypeWhitelist
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
before :cache, :check_content_type_whitelist!
|
8
|
-
end
|
9
|
-
|
10
|
-
##
|
11
|
-
# Override this method in your uploader to provide a whitelist 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]] a whitelist of content types which are allowed to be uploaded
|
18
|
-
#
|
19
|
-
# === Examples
|
20
|
-
#
|
21
|
-
# def content_type_whitelist
|
22
|
-
# %w(text/json application/json)
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# Basically the same, but using a Regexp:
|
26
|
-
#
|
27
|
-
# def content_type_whitelist
|
28
|
-
# [/(text|application)\/json/]
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
def content_type_whitelist; end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def check_content_type_whitelist!(new_file)
|
36
|
-
content_type = new_file.content_type
|
37
|
-
if content_type_whitelist && !whitelisted_content_type?(content_type)
|
38
|
-
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def whitelisted_content_type?(content_type)
|
43
|
-
Array(content_type_whitelist).any? { |item| content_type =~ /#{item}/ }
|
44
|
-
end
|
45
|
-
|
46
|
-
end # ContentTypeWhitelist
|
47
|
-
end # Uploader
|
48
|
-
end # CarrierWave
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module CarrierWave
|
2
|
-
module Uploader
|
3
|
-
module ExtensionBlacklist
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
before :cache, :check_blacklist!
|
8
|
-
end
|
9
|
-
|
10
|
-
##
|
11
|
-
# Override this method in your uploader to provide a black list 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 black list, `\A` and `\z` are automatically added to
|
16
|
-
# the Regexp expression, also case insensitive.
|
17
|
-
#
|
18
|
-
# === Returns
|
19
|
-
|
20
|
-
# [NilClass, Array[String,Regexp]] a black list of extensions which are prohibited to be uploaded
|
21
|
-
#
|
22
|
-
# === Examples
|
23
|
-
#
|
24
|
-
# def extension_black_list
|
25
|
-
# %w(swf tiff)
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# Basically the same, but using a Regexp:
|
29
|
-
#
|
30
|
-
# def extension_black_list
|
31
|
-
# [/swf/, 'tiff']
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
|
35
|
-
def extension_black_list; end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def check_blacklist!(new_file)
|
40
|
-
extension = new_file.extension.to_s
|
41
|
-
if extension_black_list and extension_black_list.detect { |item| extension =~ /\A#{item}\z/i }
|
42
|
-
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_black_list_error", :extension => new_file.extension.inspect, :prohibited_types => extension_black_list.join(", "))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module CarrierWave
|
4
|
-
module Uploader
|
5
|
-
module ExtensionWhitelist
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
before :cache, :check_whitelist!
|
10
|
-
end
|
11
|
-
|
12
|
-
##
|
13
|
-
# Override this method in your uploader to provide a white list of extensions which
|
14
|
-
# are allowed to be uploaded. Compares the file's extension case insensitive.
|
15
|
-
# Furthermore, not only strings but Regexp are allowed as well.
|
16
|
-
#
|
17
|
-
# When using a Regexp in the white list, `\A` and `\z` are automatically added to
|
18
|
-
# the Regexp expression, also case insensitive.
|
19
|
-
#
|
20
|
-
# === Returns
|
21
|
-
#
|
22
|
-
# [NilClass, Array[String,Regexp]] a white list of extensions which are allowed to be uploaded
|
23
|
-
#
|
24
|
-
# === Examples
|
25
|
-
#
|
26
|
-
# def extension_white_list
|
27
|
-
# %w(jpg jpeg gif png)
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# Basically the same, but using a Regexp:
|
31
|
-
#
|
32
|
-
# def extension_white_list
|
33
|
-
# [/jpe?g/, 'gif', 'png']
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
def extension_white_list; end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def check_whitelist!(new_file)
|
41
|
-
extension = new_file.extension.to_s
|
42
|
-
if extension_white_list and not extension_white_list.detect { |item| extension =~ /\A#{item}\z/i }
|
43
|
-
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_white_list_error", :extension => new_file.extension.inspect, :allowed_types => extension_white_list.join(", "))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end # ExtensionWhitelist
|
48
|
-
end # Uploader
|
49
|
-
end # CarrierWave
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'active_support/deprecation'
|
3
|
-
|
4
|
-
module CarrierWave
|
5
|
-
module Utilities
|
6
|
-
module Deprecation
|
7
|
-
|
8
|
-
def self.new version = '0.11.0', message = 'Carrierwave'
|
9
|
-
if ActiveSupport::VERSION::MAJOR < 4
|
10
|
-
ActiveSupport::Deprecation.warn("#{message} (will be removed from version #{version})")
|
11
|
-
else
|
12
|
-
ActiveSupport::Deprecation.new(version, message)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end # Deprecation
|
17
|
-
end # Utilities
|
18
|
-
end # CarrierWave
|