card-mod-carrierwave 0.11.0 → 0.11.5

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: 29840e46e626a7121a84faa9b4b0f9889694ab7653031bd9cf97ccb896d46263
4
- data.tar.gz: 503d37c6471c6fd8d0e6cba3c94c65097663ab0854fc24861673c80f913e1e86
3
+ metadata.gz: b3189d4e4979c66b05d69e7b09a602098410d5df3faa5cdd19a96b7b026a69bb
4
+ data.tar.gz: 774a0049c1c77d4373d5769a965734b797e916606f8ebd959ed97c39315f5646
5
5
  SHA512:
6
- metadata.gz: 65f55c9a919ea38e364f5863030d35b5674569dab60454ee157c3e78c762afbc427b3e258246d8389714e00eb752bf8076b948e8a5c70b4d202a2dd63ff01695
7
- data.tar.gz: 69c7e3184ca375b4342ad3a4f5dd2ae9f8654666e0e6cefded79f5b3c2823dfd8a074ad906acdb28b749f51413c49ebba315c7a790aa17907b1da063baf07791
6
+ metadata.gz: 2091526b0eb3da1d50ec833d7d990848a4bd6968b4595a235debccd6b5d802dcb5b32bf20a2abe6b2d0ba2679ad1d8564c755ea2d06f435563cdb08bf76e46e1
7
+ data.tar.gz: d10af461b8cc1ef9d0eaf8147274ab8e40f9a0106f87e8f153ccd2b4884ff73667fc53c6dfab8391f541dd3e80a552b06fc1d3eb03fd42d3174fdbd150653632
@@ -1,40 +1,4 @@
1
1
  module CarrierWave
2
- class << self
3
- def tmp_path
4
- @tmp_path ||= Card.paths["tmp"].existent.first
5
- end
6
- end
7
-
8
- class SanitizedFile
9
- def content_type
10
- # the original content_type method doesn't seem to be very reliable
11
- # It uses mime_magic_content_type - which returns invalid/invalid for css files
12
- # that start with a comment - as the second option. (we switch the order and
13
- # use it as the third option)
14
- @content_type ||=
15
- existing_content_type ||
16
- mini_mime_content_type ||
17
- mime_magic_content_type
18
- end
19
- end
20
-
21
- module Uploader
22
- # Implements a different name pattern for versions than CarrierWave's
23
- # default: we expect the version name at the end of the filename separated
24
- # by a dash
25
- module Versions
26
- private
27
-
28
- # put version at the end of the filename
29
- def full_filename for_file
30
- name = super(for_file)
31
- parts = name.split "."
32
- basename = [parts.shift, version_name].compact.join("-")
33
- "#{basename}.#{parts.join('.')}"
34
- end
35
- end
36
- end
37
-
38
2
  # Takes care of the file upload for cards with attached files.
39
3
  # Most of the upload behaviour depends on the card itself.
40
4
  # (e.g. card type and storage option chosen for the card). So in contrary
@@ -161,15 +125,17 @@ module CarrierWave
161
125
  #
162
126
  class FileCardUploader < Uploader::Base
163
127
  attr_accessor :mod
128
+
164
129
  include Card::Env::Location
130
+ include Path
165
131
 
166
- STORAGE_TYPES = [:cloud, :web, :coded, :local].freeze
167
- CONFIG_OPTIONS = [:provider, :attributes, :directory, :public, :credentials,
168
- :authenticated_url_expiration, :use_ssl_for_aws].freeze
169
- CONFIG_CREDENTIAL_OPTIONS = [
170
- :provider,
171
- :aws_access_key_id, :aws_secret_access_key, :region, :host, :endpoint,
172
- :google_access_key_id, :google_secret_access_key
132
+ STORAGE_TYPES = %i[cloud web coded local].freeze
133
+ CONFIG_OPTIONS = %i[provider attributes directory public credentials
134
+ authenticated_url_expiration use_ssl_for_aws].freeze
135
+ CONFIG_CREDENTIAL_OPTIONS = %i[
136
+ provider
137
+ aws_access_key_id aws_secret_access_key region host endpoint
138
+ google_access_key_id google_secret_access_key
173
139
  ].freeze
174
140
  delegate :store_dir, :retrieve_dir, :file_dir, :mod, :bucket, to: :model
175
141
 
@@ -205,6 +171,7 @@ module CarrierWave
205
171
  model.with_storage_options opts do
206
172
  return model.content if model.web?
207
173
  return "" unless file.present?
174
+
208
175
  "%s/%s" % [file_dir, url_filename]
209
176
  end
210
177
  end
@@ -230,57 +197,12 @@ module CarrierWave
230
197
  end
231
198
  end
232
199
 
233
- def local_url opts={}
234
- "%s/%s/%s" % [local_url_base(opts), file_dir, full_filename(url_filename(opts))]
235
- end
236
-
237
- def local_url_base opts={}
238
- web_path = Card.config.files_web_path
239
- opts.delete(:absolute) ? card_url(web_path) : card_path(web_path)
240
- end
241
-
242
- def public_path
243
- File.join Cardio.paths["public"].existent.first, url
244
- end
245
-
246
- def cache_dir
247
- @model.files_base_dir + "/cache"
248
- end
249
-
250
- # Carrierwave calls store_path without argument when it stores the file
251
- # and with the identifier from the db when it retrieves the file.
252
- # In our case the first part of our identifier is not part of the path
253
- # but we can construct the filename from db data. So we don't need the
254
- # identifier.
255
- def store_path for_file=nil
256
- if for_file
257
- retrieve_path
258
- else
259
- File.join([store_dir, full_filename(filename)].compact)
260
- end
261
- end
262
-
263
- def retrieve_path
264
- File.join([retrieve_dir, full_filename(filename)].compact)
265
- end
266
-
267
- def tmp_path
268
- Dir.mkdir model.tmp_upload_dir unless Dir.exist? model.tmp_upload_dir
269
- File.join model.tmp_upload_dir, filename
270
- end
271
-
272
200
  def create_versions? new_file
273
201
  model.create_versions? new_file
274
202
  end
275
203
 
276
- # paperclip compatibility used in type/file.rb#core (base format)
277
- def path version=nil
278
- version ? versions[version].path : super()
279
- end
280
-
281
204
  def original_filename
282
- @original_filename ||= model.selected_action &&
283
- model.selected_action.comment
205
+ @original_filename ||= model.selected_action&.comment
284
206
  end
285
207
 
286
208
  def action_id
@@ -288,7 +210,7 @@ module CarrierWave
288
210
  end
289
211
 
290
212
  # delegate carrierwave's fog config methods to bucket configuration
291
- ::CarrierWave::FileCardUploader::CONFIG_OPTIONS.each do |name|
213
+ CONFIG_OPTIONS.each do |name|
292
214
  define_method("fog_#{name}") { bucket_config name }
293
215
  end
294
216
 
@@ -311,9 +233,39 @@ module CarrierWave
311
233
  def storage
312
234
  case @model.storage_type
313
235
  when :cloud
314
- ::CarrierWave::Storage::Fog.new(self)
236
+ Storage::Fog.new self
315
237
  else
316
- ::CarrierWave::Storage::File.new(self)
238
+ Storage::File.new self
239
+ end
240
+ end
241
+ end
242
+
243
+ class SanitizedFile
244
+ def content_type
245
+ # the original content_type method doesn't seem to be very reliable
246
+ # It uses mime_magic_content_type - which returns invalid/invalid for css files
247
+ # that start with a comment - as the second option. (we switch the order and
248
+ # use it as the third option)
249
+ @content_type ||=
250
+ existing_content_type ||
251
+ mini_mime_content_type ||
252
+ mime_magic_content_type
253
+ end
254
+ end
255
+
256
+ module Uploader
257
+ # Implements a different name pattern for versions than CarrierWave's
258
+ # default: we expect the version name at the end of the filename separated
259
+ # by a dash
260
+ module Versions
261
+ private
262
+
263
+ # put version at the end of the filename
264
+ def full_filename for_file
265
+ name = super(for_file)
266
+ parts = name.split "."
267
+ basename = [parts.shift, version_name].compact.join("-")
268
+ "#{basename}.#{parts.join('.')}"
317
269
  end
318
270
  end
319
271
  end
@@ -0,0 +1,54 @@
1
+ module CarrierWave
2
+ def self.tmp_path
3
+ @tmp_path ||= Card.paths["tmp"].existent.first
4
+ end
5
+
6
+ class FileCardUploader
7
+ # path-related methods for uploader
8
+ module Path
9
+ def local_url opts={}
10
+ "%s/%s/%s" % [local_url_base(opts), file_dir, full_filename(url_filename(opts))]
11
+ end
12
+
13
+ def local_url_base opts={}
14
+ web_path = Card.config.files_web_path
15
+ opts.delete(:absolute) ? card_url(web_path) : card_path(web_path)
16
+ end
17
+
18
+ def public_path
19
+ File.join Cardio.paths["public"].existent.first, url
20
+ end
21
+
22
+ def cache_dir
23
+ "#{@model.files_base_dir}/cache"
24
+ end
25
+
26
+ # Carrierwave calls store_path without argument when it stores the file
27
+ # and with the identifier from the db when it retrieves the file.
28
+ # In our case the first part of our identifier is not part of the path
29
+ # but we can construct the filename from db data. So we don't need the
30
+ # identifier.
31
+ def store_path for_file=nil
32
+ if for_file
33
+ retrieve_path
34
+ else
35
+ File.join([store_dir, full_filename(filename)].compact)
36
+ end
37
+ end
38
+
39
+ def retrieve_path
40
+ File.join([retrieve_dir, full_filename(filename)].compact)
41
+ end
42
+
43
+ def tmp_path
44
+ Dir.mkdir model.tmp_upload_dir unless Dir.exist? model.tmp_upload_dir
45
+ File.join model.tmp_upload_dir, filename
46
+ end
47
+
48
+ # paperclip compatibility used in type/file.rb#core (base format)
49
+ def path version=nil
50
+ version ? versions[version].path : super()
51
+ end
52
+ end
53
+ end
54
+ end
@@ -10,7 +10,7 @@ module CarrierWave
10
10
  include CarrierWave::MiniMagick
11
11
 
12
12
  def path version=nil
13
- (version && version != :original) ? versions[version].path : super()
13
+ version && version != :original ? versions[version].path : super()
14
14
  end
15
15
 
16
16
  version :icon, if: :create_versions?, from_version: :small do
@@ -17,11 +17,13 @@ end
17
17
 
18
18
  event :save_original_filename, :prepare_to_store, on: :save, when: :file_ready_to_save? do
19
19
  return unless @current_action
20
+
20
21
  @current_action.update! comment: original_filename
21
22
  end
22
23
 
23
24
  event :validate_file_exist, :validate, on: :create do
24
25
  return if empty_ok?
26
+
25
27
  if will_be_stored_as == :web
26
28
  errors.add "url is missing" if content.blank?
27
29
  elsif !attachment.file.present?
@@ -40,12 +42,14 @@ def file_ready_to_save?
40
42
  attachment_is_changing?
41
43
  end
42
44
 
43
- def item_names _args={} # needed for flexmail attachments. hacky.
45
+ # needed for flexmail attachments. hacky.
46
+ def item_names _args={}
44
47
  [name]
45
48
  end
46
49
 
47
50
  def original_filename
48
51
  return content.split("/").last if web?
52
+
49
53
  attachment.original_filename
50
54
  end
51
55
 
@@ -75,7 +79,7 @@ end
75
79
 
76
80
  def assign_set_specific_attributes
77
81
  # reset content if we really have something to upload
78
- self.content = nil if set_specific[attachment_name.to_s].present?
82
+ self.content = nil if set_specific[attachment_name].present?
79
83
  super
80
84
  end
81
85
 
@@ -90,23 +94,42 @@ end
90
94
 
91
95
  def revision action, before_action=false
92
96
  return unless (result = super)
97
+
93
98
  result[:empty_ok] = true
94
99
  result
95
100
  end
96
101
 
97
102
  def attachment_format ext
98
- if ext.present? && attachment && (original_ext = attachment.extension.sub(/^\./, ""))
99
- if ["file", original_ext].member? ext
100
- original_ext
101
- elsif (exts = Mime::Types[attachment.content_type])
102
- if exts.find { |mt| mt.extensions.member? ext }
103
- ext
104
- else
105
- exts[0].extensions[0]
106
- end
107
- end
103
+ rescuing_extension_issues do
104
+ return unless ext.present? && original_extension
105
+
106
+ confirm_original_extension(ext) || detect_extension(ext)
108
107
  end
109
- rescue => e
108
+ end
109
+
110
+ def rescuing_extension_issues
111
+ yield
112
+ rescue StandardError => e
110
113
  Rails.logger.info "attachment_format issue: #{e.message}"
111
114
  nil
112
115
  end
116
+
117
+ def detect_extension ext
118
+ return unless (mime_types = MIME::Types[attachment.content_type])
119
+
120
+ recognized_extension?(mime_types, ext) ? ext : mime_types[0].extensions[0]
121
+ end
122
+
123
+ def recognized_extension? mime_types, ext
124
+ mime_types.find { |mt| mt.extensions.member? ext }
125
+ end
126
+
127
+ def confirm_original_extension ext
128
+ return unless ["file", original_extension].member? ext
129
+
130
+ original_extension
131
+ end
132
+
133
+ def original_extension
134
+ @original_extension ||= attachment&.extension&.sub(/^\./, "")
135
+ end
@@ -11,7 +11,7 @@ event :validate_storage_type_update, :validate, on: :update, when: :cloud? do
11
11
  # `update storage_type: :local, file: [file handle]` is ok
12
12
  return unless storage_type_changed? && !attachment_is_changing?
13
13
 
14
- errors.add :storage_type, tr(:moving_files_is_not_supported)
14
+ errors.add :storage_type, t(:carrierwave_moving_files_is_not_supported)
15
15
  end
16
16
 
17
17
  def bucket
@@ -20,6 +20,7 @@ end
20
20
 
21
21
  def new_card_bucket
22
22
  return unless new_card?
23
+
23
24
  # If the file is assigned before the bucket option we have to
24
25
  # check if there is a bucket options in set_specific.
25
26
  # That happens for exmaple when the file appears before the bucket in the
@@ -34,6 +35,7 @@ end
34
35
 
35
36
  def load_bucket_config
36
37
  return {} unless bucket
38
+
37
39
  bucket_config = Cardio.config.file_buckets&.dig(bucket.to_sym) || {}
38
40
  bucket_config.symbolize_keys!
39
41
  bucket_config[:credentials]&.symbolize_keys!
@@ -96,6 +98,7 @@ def each_credential_from_env
96
98
  regexp = credential_from_env_regexp
97
99
  ENV.each_key do |env_key|
98
100
  next unless (m = regexp.match env_key)
101
+
99
102
  yield m[:option].downcase.to_sym
100
103
  end
101
104
  end
@@ -112,6 +115,7 @@ end
112
115
 
113
116
  def bucket_from_content
114
117
  return unless content
118
+
115
119
  content.match(/^\((?<bucket>[^)]+)\)/) { |m| m[:bucket] }
116
120
  end
117
121
 
@@ -1,12 +1,17 @@
1
1
  event :lose_coded_status_on_update, :initialize, on: :update, when: :coded? do
2
2
  # unless explicit
3
3
  return if @new_mod
4
+
4
5
  @new_storage_type ||= storage_type_from_config
5
6
  end
6
7
 
7
8
  event :validate_coded_storage_type, :validate, on: :save, when: :will_become_coded? do
8
- errors.add :storage_type, tr(:mod_argument_needed_to_save) unless mod || @new_mod
9
- errors.add :storage_type, tr(:codename_needed_for_storage) if codename.blank?
9
+ storage_type_error :mod_argument_needed_to_save unless mod || @new_mod
10
+ storage_type_error :codename_needed_for_storage if codename.blank?
11
+ end
12
+
13
+ def storage_type_error error_name
14
+ errors.add :storage_type, t("carrierwave_#{error_name}")
10
15
  end
11
16
 
12
17
  def will_become_coded?
@@ -1,4 +1,3 @@
1
-
2
1
  event :update_public_link_on_create, :integrate, on: :create, when: :local? do
3
2
  update_public_link
4
3
  end
@@ -9,6 +8,7 @@ end
9
8
 
10
9
  event :update_public_link, after: :update_read_rule, when: :local? do
11
10
  return if content.blank?
11
+
12
12
  if who_can(:read).include? Card::AnyoneID
13
13
  create_public_links
14
14
  else
@@ -21,6 +21,7 @@ private
21
21
  def create_public_links
22
22
  path = attachment.public_path
23
23
  return if File.exist? path
24
+
24
25
  FileUtils.mkdir_p File.dirname(path)
25
26
  File.symlink attachment.path, path unless File.symlink? path
26
27
  create_versions_public_links
@@ -29,6 +30,7 @@ end
29
30
  def create_versions_public_links
30
31
  attachment.versions.each_value do |version|
31
32
  next if File.symlink? version.public_path
33
+
32
34
  File.symlink version.path, version.public_path
33
35
  end
34
36
  end
@@ -36,5 +38,6 @@ end
36
38
  def remove_public_links
37
39
  symlink_dir = File.dirname attachment.public_path
38
40
  return unless Dir.exist? symlink_dir
41
+
39
42
  FileUtils.rm_rf symlink_dir
40
43
  end
@@ -25,6 +25,7 @@ def mod_dir new_mod=nil
25
25
  dir = Cardio::Mod.dirs.path(mod_name) || (mod_name.to_sym == :test && "test")
26
26
 
27
27
  raise Error, "can't find mod \"#{mod_name}\"" unless dir
28
+
28
29
  dir
29
30
  end
30
31
 
@@ -14,12 +14,9 @@ event :storage_type_change, :store, on: :update, when: :storage_type_changed? do
14
14
  end
15
15
 
16
16
  event :validate_storage_type, :validate, on: :save do
17
- unless known_storage_type? will_be_stored_as
18
- errors.add :storage_type, tr(
19
- :unknown_storage_type,
20
- new_storage_type: @new_storage_type
21
- )
22
- end
17
+ return if known_storage_type? will_be_stored_as
18
+
19
+ errors.add :storage_type, unknown_storage_type(@new_storage_type)
23
20
  end
24
21
 
25
22
  def will_be_stored_as
@@ -64,8 +61,8 @@ def mod
64
61
  end
65
62
 
66
63
  def mod_from_content
67
- if content =~ %r{^:[^/]+/([^.]+)}
68
- Regexp.last_match(1) # current mod_file format
64
+ if (m = content.match %r{^:[^/]+/([^.]+)})
65
+ m[1] # current mod_file format
69
66
  else
70
67
  mod_from_deprecated_content
71
68
  end
@@ -73,8 +70,9 @@ end
73
70
 
74
71
  # old format is still used in card_changes
75
72
  def mod_from_deprecated_content
76
- return if content =~ /^\~/
73
+ return if content.match?(/^~/)
77
74
  return unless (lines = content.split("\n")) && lines.size == 4
75
+
78
76
  lines.last
79
77
  end
80
78
 
@@ -93,15 +91,15 @@ def valid_storage_type_list
93
91
  end
94
92
 
95
93
  def invalid_storage_type! type
96
- raise Card::Error, tr(:error_invalid_storage_type, type: type)
94
+ raise Card::Error, t(:carrierwave_error_invalid_storage_type, type: type)
97
95
  end
98
96
 
99
97
  def storage_type_from_content
100
98
  case content
101
- when /^\(/ then :cloud
102
- when %r{/^https?\:/} then :web
103
- when /^~/ then :local
104
- when /^\:/ then :coded
99
+ when /^\(/ then :cloud
100
+ when %r{/^https?:/} then :web
101
+ when /^~/ then :local
102
+ when /^:/ then :coded
105
103
  else
106
104
  if deprecated_mod_file?
107
105
  :coded
@@ -123,7 +121,7 @@ end
123
121
 
124
122
  def storage_type= value
125
123
  known_storage_type? value
126
- if @action == :update #&& storage_type != value
124
+ if @action == :update # && storage_type != value
127
125
  # we cant update the storage type directly here
128
126
  # if we do then the uploader doesn't find the file we want to update
129
127
  @new_storage_type = value
@@ -133,19 +131,22 @@ def storage_type= value
133
131
  end
134
132
 
135
133
  def with_storage_options opts={}
136
- old_values = {}
134
+ old_values = stash_and_set_storage_options opts
137
135
  validate_temporary_storage_type_change opts[:storage_type]
138
- %i[storage_type mod bucket].each do |opt_name|
139
- next unless opts[opt_name]
140
- old_values[opt_name] = instance_variable_get "@#{opt_name}"
141
- instance_variable_set "@#{opt_name}", opts[opt_name]
142
- @temp_storage_type = true
143
- end
136
+ @temp_storage_type = true
144
137
  yield
145
138
  ensure
146
139
  @temp_storage_type = false
147
- old_values.each do |key, val|
148
- instance_variable_set "@#{key}", val
140
+ old_values.each { |key, val| instance_variable_set "@#{key}", val }
141
+ end
142
+
143
+ def stash_and_set_storage_options opts
144
+ %i[storage_type mod bucket].each_with_object({}) do |opt_name, old_values|
145
+ next unless opts[opt_name]
146
+
147
+ old_values[opt_name] = instance_variable_get "@#{opt_name}"
148
+ instance_variable_set "@#{opt_name}", opts[opt_name]
149
+ old_values
149
150
  end
150
151
  end
151
152
 
@@ -153,14 +154,10 @@ def temporary_storage_type_change?
153
154
  @temp_storage_type
154
155
  end
155
156
 
156
- def validate_temporary_storage_type_change new_storage_type=nil
157
- new_storage_type ||= @new_storage_type
158
- return unless new_storage_type
159
- unless known_storage_type? new_storage_type
160
- raise Error, tr(:unknown_storage_type, new_storage_type: new_storage_type)
161
- end
162
-
163
- if new_storage_type == :coded && codename.blank?
157
+ def validate_temporary_storage_type_change type=nil
158
+ return unless type ||= @new_storage_type
159
+ raise Error, unknown_storage_type(type) unless known_storage_type? type
160
+ if type == :coded && codename.blank?
164
161
  raise Error, "codename needed for storage type :coded"
165
162
  end
166
163
  end
@@ -168,3 +165,7 @@ end
168
165
  def known_storage_type? type=storage_type
169
166
  type.in? CarrierWave::FileCardUploader::STORAGE_TYPES
170
167
  end
168
+
169
+ def unknown_storage_type type
170
+ t :carrierwave_unknown_storage_type, new_storage_type: type
171
+ end
@@ -27,6 +27,7 @@ end
27
27
  event :assign_attachment_on_create, :initialize,
28
28
  after: :assign_action, on: :create, when: :save_preliminary_upload? do
29
29
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
30
+
30
31
  upload_cache_card.selected_action_id = action.id
31
32
  upload_cache_card.select_file_revision
32
33
  assign_attachment upload_cache_card.attachment.file, action.comment
@@ -35,6 +36,7 @@ end
35
36
  event :assign_attachment_on_update, :initialize,
36
37
  after: :assign_action, on: :update, when: :save_preliminary_upload? do
37
38
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
39
+
38
40
  uploaded_file = with_selected_action_id(action.id) { attachment.file }
39
41
  assign_attachment uploaded_file, action.comment
40
42
  end
@@ -48,6 +50,7 @@ end
48
50
  event :delete_cached_upload_file_on_create, :integrate,
49
51
  on: :create, when: :save_preliminary_upload? do
50
52
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
53
+
51
54
  upload_cache_card.delete_files_for_action action
52
55
  action.delete
53
56
  end
@@ -61,6 +64,7 @@ end
61
64
  event :delete_cached_upload_file_on_update, :integrate,
62
65
  on: :update, when: :save_preliminary_upload? do
63
66
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
67
+
64
68
  delete_files_for_action action
65
69
  action.delete
66
70
  end
data/set/self/favicon.rb CHANGED
@@ -6,6 +6,7 @@ format :html do
6
6
 
7
7
  view :link_tag, perms: :none do
8
8
  return unless (source = render :source, size: :small)
9
+
9
10
  tag :link, rel: "shortcut icon", href: source
10
11
  end
11
12
 
data/set/type/file.rb CHANGED
@@ -9,8 +9,9 @@ module SelectedAction
9
9
 
10
10
  def last_content_action_id
11
11
  return super if temporary_storage_type_change?
12
+
12
13
  # find action id from content (saves lookups)
13
- db_content.to_s.split(%r{[/\.]})[-2]
14
+ db_content.to_s.split(%r{[/.]})[-2]
14
15
  end
15
16
  end
16
17
  include SelectedAction
@@ -19,6 +20,7 @@ format do
19
20
  view :source do
20
21
  file = card.attachment
21
22
  return "" unless file.valid?
23
+
22
24
  contextualize_path file.url
23
25
  end
24
26
 
@@ -33,17 +35,26 @@ format do
33
35
  end
34
36
 
35
37
  def handle_source
36
- source = _render_source
37
- return "" if source.blank?
38
- block_given? ? yield(source) : source
39
- rescue => e
40
- Rails.logger.info "Error with file source: #{e.message}"
41
- tr :file_error
38
+ rescuing_file_source_error do
39
+ source = _render_source
40
+ return "" if source.blank?
41
+
42
+ block_given? ? yield(source) : source
43
+ end
42
44
  end
43
45
 
44
46
  def selected_version
45
47
  card.attachment
46
48
  end
49
+
50
+ private
51
+
52
+ def rescuing_file_source_error
53
+ yield
54
+ rescue StandardError => e
55
+ Rails.logger.info "Error with file source: #{e.message}"
56
+ t :carrierwave_file_error
57
+ end
47
58
  end
48
59
 
49
60
  format :file do
@@ -53,6 +64,7 @@ format :file do
53
64
  attachment_format = card.attachment_format(params[:format])
54
65
  return _render_not_found unless attachment_format
55
66
  return card.format(:html).render_core if card.remote_storage?
67
+
56
68
  set_response_headers
57
69
  args_for_send_file
58
70
  end
@@ -60,13 +72,14 @@ format :file do
60
72
  def args_for_send_file
61
73
  file = selected_version
62
74
  [file.path, { type: file.content_type,
63
- filename: "#{card.name.safe_key}#{file.extension}",
75
+ filename: "#{card.name.safe_key}#{file.extension}",
64
76
  x_sendfile: true,
65
77
  disposition: (params[:format] == "file" ? "attachment" : "inline") }]
66
78
  end
67
79
 
68
80
  def set_response_headers
69
81
  return unless params[:explicit_file] && (response = controller&.response)
82
+
70
83
  response.headers["Expires"] = 1.year.from_now.httpdate
71
84
  # currently using default "private", because proxy servers could block
72
85
  # needed permission checks
@@ -74,10 +87,14 @@ format :file do
74
87
  end
75
88
  end
76
89
 
90
+ format :json do
91
+ view(:content) { render_core }
92
+ end
93
+
77
94
  format :html do
78
95
  view :core do
79
96
  handle_source do |source|
80
- "<a href=\"#{source}\">#{tr :download, title: title_in_context(voo.title)}</a>"
97
+ haml :core, source: source
81
98
  end
82
99
  end
83
100
 
@@ -111,6 +128,6 @@ format :html do
111
128
  end
112
129
 
113
130
  def preview_editor_delete_text
114
- tr :delete
131
+ t :carrierwave_delete
115
132
  end
116
133
  end
@@ -0,0 +1,2 @@
1
+ %a{ href: source }<
2
+ = t :carrierwave_download, title: title_in_context(voo.title)
data/set/type/image.rb CHANGED
@@ -23,8 +23,10 @@ format do
23
23
 
24
24
  view :source do
25
25
  return card.content if card.web?
26
+
26
27
  image = selected_version
27
28
  return "" unless image.valid?
29
+
28
30
  contextualize_path image.url
29
31
  end
30
32
 
@@ -37,10 +39,6 @@ format do
37
39
  end
38
40
  end
39
41
 
40
- def handle_source
41
- super
42
- end
43
-
44
42
  def closed_size
45
43
  :icon
46
44
  end
@@ -70,11 +68,16 @@ format do
70
68
  end
71
69
  end
72
70
 
71
+ format :json do
72
+ include File::JsonFormat
73
+ end
74
+
73
75
  format :email_html do
74
76
  view :inline, cache: :never do
75
77
  handle_source do |source|
76
78
  return source unless (mail = inherit :active_mail) &&
77
79
  ::File.exist?(path = selected_version.path)
80
+
78
81
  url = attach_image mail, path
79
82
  image_tag url
80
83
  end
@@ -4,6 +4,7 @@ format :html do
4
4
  # core HTML image view.
5
5
  view :core do
6
6
  return card.attachment.read if card.svg?
7
+
7
8
  with_valid_source do |source|
8
9
  image_tag source, alt: card.name
9
10
  end
@@ -34,6 +35,7 @@ format :html do
34
35
 
35
36
  def preview
36
37
  return if card.new_card? && !card.preliminary_upload?
38
+
37
39
  wrap_with :div, class: "attachment-preview",
38
40
  id: "#{card.attachment.filename}-preview" do
39
41
  _render_core size: :medium
@@ -55,12 +57,20 @@ format :html do
55
57
 
56
58
  def old_image action, hide_diff
57
59
  return if hide_diff || !action
58
- return unless (last_change = card.last_change_on(:db_content, before: action))
59
- card.with_selected_action_id last_change.card_action_id do
60
- Card::Content::Diff.render_deleted_chunk _render_core
60
+
61
+ old_image_change action do |old_action_id|
62
+ card.with_selected_action_id old_action_id do
63
+ Card::Content::Diff.render_deleted_chunk _render_core
64
+ end
61
65
  end
62
66
  end
63
67
 
68
+ def old_image_change action
69
+ return unless (change = card.last_change_on(:db_content, before: action))
70
+
71
+ yield change.card_action_id
72
+ end
73
+
64
74
  def new_image action
65
75
  card.with_selected_action_id action.id do
66
76
  Card::Content::Diff.render_added_chunk _render_core
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.11.0
4
+ version: 0.11.5
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: 2020-12-24 00:00:00.000000000 Z
13
+ date: 2021-05-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,28 +18,28 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.101.0
21
+ version: 1.101.5
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.101.0
28
+ version: 1.101.5
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.0.2
35
+ version: 2.2.1
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.0.2
42
+ version: 2.2.1
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: mini_magick
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -60,28 +60,28 @@ dependencies:
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.11.0
63
+ version: 0.11.5
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: 0.11.0
70
+ version: 0.11.5
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: card-mod-permissions
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.11.0
77
+ version: 0.11.5
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - '='
83
83
  - !ruby/object:Gem::Version
84
- version: 0.11.0
84
+ version: 0.11.5
85
85
  description: ''
86
86
  email:
87
87
  - info@decko.org
@@ -92,6 +92,7 @@ files:
92
92
  - config/core_initializers/carrierwave.rb
93
93
  - lib/carrier_wave/card_mount.rb
94
94
  - lib/carrier_wave/file_card_uploader.rb
95
+ - lib/carrier_wave/file_card_uploader/path.rb
95
96
  - lib/carrier_wave/image_card_uploader.rb
96
97
  - set/abstract/attachment.rb
97
98
  - set/abstract/attachment/cloud.rb
@@ -107,14 +108,20 @@ files:
107
108
  - set/self/new_file.rb
108
109
  - set/self/new_image.rb
109
110
  - set/type/file.rb
111
+ - set/type/file/core.haml
110
112
  - set/type/file/file_chooser.haml
111
113
  - set/type/file/preview_editor.haml
112
114
  - set/type/image.rb
113
115
  - set/type/image/html_views.rb
114
- homepage: http://decko.org
116
+ homepage: https://decko.org
115
117
  licenses:
116
118
  - GPL-3.0
117
119
  metadata:
120
+ source_code_uri: https://github.com/decko-commons/decko
121
+ homepage_uri: https://decko.org
122
+ bug_tracker_uri: https://github.com/decko-commons/decko/issues
123
+ wiki_uri: https://decko.org
124
+ documentation_url: http://docs.decko.org/
118
125
  card-mod: carrierwave
119
126
  post_install_message:
120
127
  rdoc_options: []
@@ -131,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
138
  - !ruby/object:Gem::Version
132
139
  version: '0'
133
140
  requirements: []
134
- rubygems_version: 3.0.3
141
+ rubygems_version: 3.1.4
135
142
  signing_key:
136
143
  specification_version: 4
137
144
  summary: File and Image handling