card-mod-carrierwave 0.16.0 → 0.17.0

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: f91d51960354436b85df108967757650bdd9713965eedd25f7f7e03092e2ae58
4
- data.tar.gz: aa239da9035dcb91b615dcd634981c22a8b061630f10f394e6776ff291b7ecc8
3
+ metadata.gz: 88a2af21e5caf0c6c695e722cc3a97b27366a0efa2d52f5e13bb1722ec979731
4
+ data.tar.gz: cf3f344bd209ddf88b85b4b037660254ab8c82aea5cf0d0138c8f1fa31b40165
5
5
  SHA512:
6
- metadata.gz: 6d7fbddc2d23f057e739048afe54aa1793b3a6ee6cef889ff84978838b3bc55b1bd5b225654491c6dc85b14ab9fd75d56c3e94eceae1143fc9a375d8c5600705
7
- data.tar.gz: 7b7316b9ff90b00a3248d9bad5ca535509137bb44083465a5236d415d8fb65997408fe8d07e6223000b218aa0aebdbccfc25074509f314313401c372204f1585
6
+ metadata.gz: 259779a3dbf7d7bbe4106a9630f2afd8fdcee17bb2283f3f99504e533368d02f534fbd0269708f74dce01c9bc995587faebfc8c682ac7975683e6f29bfedc9ee
7
+ data.tar.gz: 71ad7c23e067986dcc1cc6f3f4301f2e87806dc83cab3763dc77658bc029ed570e75fd098cfe3d4418655228419e078dd878cc4050bdaf2fc4a61fec2d33241d
data/config/admin.yml ADDED
@@ -0,0 +1,4 @@
1
+ cardtypes:
2
+ upload:
3
+ - file
4
+ - image
@@ -1,7 +1,10 @@
1
1
  require "carrierwave"
2
2
 
3
3
  module CarrierWave
4
- # adapt carrierwave mount to cards
4
+ # Adapt carrierwave mount to cards.
5
+ # We translate the active record hooks in
6
+ # https://github.com/carrierwaveuploader/carrierwave/blob/v3.0.5/lib/carrierwave/orm/activerecord.rb
7
+ # to card events.
5
8
  module CardMount
6
9
  include CarrierWave::Mount
7
10
 
@@ -18,14 +21,12 @@ module CarrierWave
18
21
  super
19
22
 
20
23
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
21
- event :store_#{column}_event, :finalize,
22
- on: :save, when: :store_#{column}_event? do
24
+ event :store_#{column}_event, :finalize, when: :store_#{column}_event? do
23
25
  store_#{column}!
24
26
  end
25
27
 
26
28
  # remove files only if card has no history
27
- event :remove_#{column}_event, :finalize,
28
- on: :delete, when: proc { |c| !c.history? } do
29
+ event :remove_#{column}_event, :finalize, on: :delete, when: :no_history? do
29
30
  remove_#{column}!
30
31
  end
31
32
 
@@ -33,13 +34,13 @@ module CarrierWave
33
34
  mark_remove_#{column}_false
34
35
  end
35
36
 
36
- event :store_previous_changes_for_#{column}_event, :store,
37
- on: :update, when: proc { |c| !c.history? } do
38
- store_previous_changes_for_#{column}
37
+ event :reset_previous_changes_for_#{column}_event, :finalize,
38
+ when: :no_history? do
39
+ reset_previous_changes_for_#{column}
39
40
  end
40
41
 
41
- event :remove_previously_stored_#{column}_event, :finalize,
42
- on: :update, when: proc { |c| !c.history?} do
42
+ event :remove_previously_stored_#{column}_event, :finalize, on: :update,
43
+ when: :no_history? do
43
44
  remove_previously_stored_#{column}
44
45
  end
45
46
 
@@ -61,13 +62,8 @@ module CarrierWave
61
62
  "#{column}".to_sym
62
63
  end
63
64
 
64
- def read_uploader *args
65
- read_attribute *args
66
- end
67
-
68
- def write_uploader *args
69
- write_attribute *args
70
- end
65
+ def read_uploader *args; read_attribute *args; end
66
+ def write_uploader *args; write_attribute *args; end
71
67
 
72
68
  def #{column}=(new_file)
73
69
  return if new_file.blank?
@@ -128,7 +124,20 @@ module CarrierWave
128
124
  end
129
125
  end
130
126
  end
127
+
128
+ def reload(*)
129
+ @_mounters = nil
130
+ super
131
+ end
131
132
  RUBY
132
133
  end
133
134
  end
135
+
136
+ # The temporary identifiers from Carrierwave's mounters kill CardMount;
137
+ # We don't seem to need them.
138
+ class Mounter
139
+ def write_temporary_identifier
140
+ # noop
141
+ end
142
+ end
134
143
  end
@@ -175,6 +175,10 @@ module CarrierWave
175
175
  end
176
176
  end
177
177
 
178
+ def temporary_identifier
179
+ db_content
180
+ end
181
+
178
182
  # @option opts [Symbol] :absolute - return absolute url
179
183
  def url opts={}
180
184
  if model.cloud?
@@ -234,13 +238,26 @@ module CarrierWave
234
238
  class SanitizedFile
235
239
  def content_type
236
240
  # the original content_type method doesn't seem to be very reliable
237
- # It uses mime_magic_content_type - which returns invalid/invalid for css files
238
- # that start with a comment - as the second option. (we switch the order and
239
- # use it as the third option)
241
+ # It uses declared_content_type - which sometimes returns "text/plain" for asset
242
+ # files for unknown reasons. (we switch the order and use it as the third option)
240
243
  @content_type ||=
241
- existing_content_type ||
242
- mini_mime_content_type ||
243
- mime_magic_content_type
244
+ guessed_safe_content_type ||
245
+ identified_content_type ||
246
+ declared_content_type ||
247
+ Marcel::MimeType::BINARY
248
+ end
249
+
250
+ def guessed_safe_content_type
251
+ # overrides the default method which was returning "application/javascript" instead
252
+ # of "text/javascript" for our .js files.
253
+ return unless path
254
+
255
+ type = Marcel::Magic.by_path(original_filename).to_s
256
+ if type.start_with? "text/", "application/json'"
257
+ type
258
+ elsif type == "application/javascript"
259
+ "text/javascript"
260
+ end
244
261
  end
245
262
  end
246
263
 
@@ -254,6 +271,8 @@ module CarrierWave
254
271
  # put version at the end of the filename
255
272
  def full_filename for_file
256
273
  name = super(for_file)
274
+ return unless name.present?
275
+
257
276
  parts = name.split "."
258
277
  basename = [parts.shift, version_name].compact.join("-")
259
278
  "#{basename}.#{parts.join('.')}"
@@ -3,7 +3,7 @@ require "mini_magick"
3
3
  module CarrierWave
4
4
  # Adds image specific version handling to {FileCardUploader}.
5
5
  # The ImageCardUploader creates five versions of different sizes when it
6
- # uploads an imagae file:
6
+ # uploads an image file:
7
7
  # icon (16x16), small (75x75), medium (200X200), large (500x500) and
8
8
  # the original size.
9
9
  class ImageCardUploader < FileCardUploader
@@ -48,7 +48,7 @@ module CarrierWave
48
48
  # add 'original' if no version is given
49
49
  def full_filename for_file
50
50
  name = super(for_file)
51
- if version_name
51
+ if name.blank? || version_name
52
52
  name
53
53
  else
54
54
  parts = name.split "."
@@ -29,13 +29,17 @@ def storage_type_error error_name
29
29
  end
30
30
 
31
31
  def mod_from_content
32
- if (m = content&.match %r{^:[^/]+/([^.]+)})
32
+ if (m = mod_name_match content)
33
33
  m[1] # current mod_file format
34
34
  else
35
35
  mod_from_deprecated_content
36
36
  end
37
37
  end
38
38
 
39
+ def mod_name_match cont
40
+ cont&.match %r{^:[^/]+/([^.]+)}
41
+ end
42
+
39
43
  # place for files of mod file cards
40
44
  def coded_dir new_mod=nil
41
45
  dir = File.join mod_dir(new_mod), MOD_FILE_DIR, codename.to_s
data/set/type/file.rb CHANGED
@@ -69,12 +69,24 @@ format :file do
69
69
  args_for_send_file
70
70
  end
71
71
 
72
+ private
73
+
72
74
  def args_for_send_file
73
75
  file = selected_version
74
76
  [file.path, { type: file.content_type,
75
77
  filename: "#{card.name.safe_key}#{file.extension}",
76
78
  x_sendfile: true,
77
- disposition: (params[:format] == "file" ? "attachment" : "inline") }]
79
+ disposition: disposition }]
80
+ end
81
+
82
+ def disposition
83
+ if params[:disposition]
84
+ params[:disposition]
85
+ elsif params[:format] == "file"
86
+ "attachment"
87
+ else
88
+ "inline"
89
+ end
78
90
  end
79
91
 
80
92
  def set_response_headers
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-11-18 00:00:00.000000000 Z
13
+ date: 2024-06-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,84 +18,98 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.106.0
21
+ version: 1.107.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.106.0
28
+ version: 1.107.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: carrierwave
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '2.2'
35
+ version: '3.0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '2.2'
42
+ version: '3.0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: mini_magick
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '4.2'
49
+ version: '4.12'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '4.2'
56
+ version: '4.12'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: ssrf_filter
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 1.0.7
63
+ version: '1.1'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: 1.0.7
70
+ version: '1.1'
71
+ - !ruby/object:Gem::Dependency
72
+ name: marcel
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.2
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '='
83
+ - !ruby/object:Gem::Version
84
+ version: 1.0.2
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: card-mod-history
73
87
  requirement: !ruby/object:Gem::Requirement
74
88
  requirements:
75
89
  - - '='
76
90
  - !ruby/object:Gem::Version
77
- version: 0.16.0
91
+ version: 0.17.0
78
92
  type: :runtime
79
93
  prerelease: false
80
94
  version_requirements: !ruby/object:Gem::Requirement
81
95
  requirements:
82
96
  - - '='
83
97
  - !ruby/object:Gem::Version
84
- version: 0.16.0
98
+ version: 0.17.0
85
99
  - !ruby/object:Gem::Dependency
86
100
  name: card-mod-permissions
87
101
  requirement: !ruby/object:Gem::Requirement
88
102
  requirements:
89
103
  - - '='
90
104
  - !ruby/object:Gem::Version
91
- version: 0.16.0
105
+ version: 0.17.0
92
106
  type: :runtime
93
107
  prerelease: false
94
108
  version_requirements: !ruby/object:Gem::Requirement
95
109
  requirements:
96
110
  - - '='
97
111
  - !ruby/object:Gem::Version
98
- version: 0.16.0
112
+ version: 0.17.0
99
113
  description: ''
100
114
  email:
101
115
  - info@decko.org
@@ -107,6 +121,7 @@ files:
107
121
  - README.md
108
122
  - assets/script/upload.js.coffee
109
123
  - assets/style/file.scss
124
+ - config/admin.yml
110
125
  - config/early/carrierwave.rb
111
126
  - config/early/mini_magick.rb
112
127
  - config/locales/de.yml
@@ -173,14 +188,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
188
  requirements:
174
189
  - - ">="
175
190
  - !ruby/object:Gem::Version
176
- version: '2.5'
191
+ version: '3.0'
177
192
  required_rubygems_version: !ruby/object:Gem::Requirement
178
193
  requirements:
179
194
  - - ">="
180
195
  - !ruby/object:Gem::Version
181
196
  version: '0'
182
197
  requirements: []
183
- rubygems_version: 3.4.10
198
+ rubygems_version: 3.5.10
184
199
  signing_key:
185
200
  specification_version: 4
186
201
  summary: File and Image handling