activestorage 6.1.5 → 7.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activestorage might be problematic. Click here for more details.

Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +181 -208
  3. data/README.md +25 -11
  4. data/app/assets/javascripts/activestorage.esm.js +844 -0
  5. data/app/assets/javascripts/activestorage.js +257 -376
  6. data/app/controllers/active_storage/base_controller.rb +0 -9
  7. data/app/controllers/active_storage/blobs/proxy_controller.rb +15 -4
  8. data/app/controllers/active_storage/blobs/redirect_controller.rb +6 -4
  9. data/app/controllers/active_storage/disk_controller.rb +1 -0
  10. data/app/controllers/active_storage/representations/base_controller.rb +5 -1
  11. data/app/controllers/active_storage/representations/proxy_controller.rb +7 -3
  12. data/app/controllers/active_storage/representations/redirect_controller.rb +6 -4
  13. data/app/controllers/concerns/active_storage/set_blob.rb +6 -2
  14. data/app/controllers/concerns/active_storage/set_current.rb +3 -3
  15. data/app/controllers/concerns/active_storage/streaming.rb +65 -0
  16. data/app/javascript/activestorage/ujs.js +1 -1
  17. data/app/models/active_storage/attachment.rb +35 -2
  18. data/app/models/active_storage/blob/representable.rb +7 -5
  19. data/app/models/active_storage/blob.rb +92 -36
  20. data/app/models/active_storage/current.rb +12 -2
  21. data/app/models/active_storage/preview.rb +6 -4
  22. data/app/models/active_storage/record.rb +1 -1
  23. data/app/models/active_storage/variant.rb +3 -6
  24. data/app/models/active_storage/variant_record.rb +2 -0
  25. data/app/models/active_storage/variant_with_record.rb +9 -5
  26. data/app/models/active_storage/variation.rb +2 -2
  27. data/config/routes.rb +10 -10
  28. data/db/migrate/20170806125915_create_active_storage_tables.rb +32 -11
  29. data/db/update_migrate/20190112182829_add_service_name_to_active_storage_blobs.rb +4 -0
  30. data/db/update_migrate/20191206030411_create_active_storage_variant_records.rb +17 -2
  31. data/db/update_migrate/20211119233751_remove_not_null_on_active_storage_blobs_checksum.rb +7 -0
  32. data/lib/active_storage/analyzer/audio_analyzer.rb +65 -0
  33. data/lib/active_storage/analyzer/image_analyzer/image_magick.rb +39 -0
  34. data/lib/active_storage/analyzer/image_analyzer/vips.rb +49 -0
  35. data/lib/active_storage/analyzer/image_analyzer.rb +2 -30
  36. data/lib/active_storage/analyzer/video_analyzer.rb +27 -12
  37. data/lib/active_storage/analyzer.rb +8 -4
  38. data/lib/active_storage/attached/changes/create_many.rb +7 -3
  39. data/lib/active_storage/attached/changes/create_one.rb +1 -1
  40. data/lib/active_storage/attached/changes/create_one_of_many.rb +1 -1
  41. data/lib/active_storage/attached/changes/delete_many.rb +1 -1
  42. data/lib/active_storage/attached/changes/delete_one.rb +1 -1
  43. data/lib/active_storage/attached/changes/detach_many.rb +18 -0
  44. data/lib/active_storage/attached/changes/detach_one.rb +24 -0
  45. data/lib/active_storage/attached/changes/purge_many.rb +27 -0
  46. data/lib/active_storage/attached/changes/purge_one.rb +27 -0
  47. data/lib/active_storage/attached/changes.rb +7 -1
  48. data/lib/active_storage/attached/many.rb +27 -15
  49. data/lib/active_storage/attached/model.rb +35 -7
  50. data/lib/active_storage/attached/one.rb +32 -27
  51. data/lib/active_storage/downloader.rb +4 -4
  52. data/lib/active_storage/engine.rb +59 -17
  53. data/lib/active_storage/fixture_set.rb +76 -0
  54. data/lib/active_storage/gem_version.rb +4 -4
  55. data/lib/active_storage/previewer.rb +4 -4
  56. data/lib/active_storage/reflection.rb +12 -2
  57. data/lib/active_storage/service/azure_storage_service.rb +28 -6
  58. data/lib/active_storage/service/configurator.rb +1 -1
  59. data/lib/active_storage/service/disk_service.rb +24 -19
  60. data/lib/active_storage/service/gcs_service.rb +109 -11
  61. data/lib/active_storage/service/mirror_service.rb +2 -2
  62. data/lib/active_storage/service/registry.rb +1 -1
  63. data/lib/active_storage/service/s3_service.rb +37 -15
  64. data/lib/active_storage/service.rb +13 -5
  65. data/lib/active_storage/transformers/image_processing_transformer.rb +7 -294
  66. data/lib/active_storage/transformers/transformer.rb +1 -1
  67. data/lib/active_storage/version.rb +1 -1
  68. data/lib/active_storage.rb +293 -1
  69. metadata +28 -18
  70. data/app/controllers/concerns/active_storage/set_headers.rb +0 -12
@@ -35,8 +35,8 @@ module ActiveStorage
35
35
  # can configure the service to use like this:
36
36
  #
37
37
  # ActiveStorage::Blob.service = ActiveStorage::Service.configure(
38
- # :Disk,
39
- # root: Pathname("/foo/bar/storage")
38
+ # :local,
39
+ # { local: {service: "Disk", root: Pathname("/tmp/foo/storage") } }
40
40
  # )
41
41
  class Service
42
42
  extend ActiveSupport::Autoload
@@ -57,7 +57,7 @@ module ActiveStorage
57
57
  # Passes the configurator and all of the service's config as keyword args.
58
58
  #
59
59
  # See MirrorService for an example.
60
- def build(configurator:, name:, service: nil, **service_config) #:nodoc:
60
+ def build(configurator:, name:, service: nil, **service_config) # :nodoc:
61
61
  new(**service_config).tap do |service_instance|
62
62
  service_instance.name = name
63
63
  end
@@ -90,6 +90,11 @@ module ActiveStorage
90
90
  ActiveStorage::Downloader.new(self).open(*args, **options, &block)
91
91
  end
92
92
 
93
+ # Concatenate multiple files into a single "composed" file.
94
+ def compose(source_keys, destination_key, filename: nil, content_type: nil, disposition: nil, custom_metadata: {})
95
+ raise NotImplementedError
96
+ end
97
+
93
98
  # Delete the file at the +key+.
94
99
  def delete(key)
95
100
  raise NotImplementedError
@@ -128,12 +133,12 @@ module ActiveStorage
128
133
  # The URL will be valid for the amount of seconds specified in +expires_in+.
129
134
  # You must also provide the +content_type+, +content_length+, and +checksum+ of the file
130
135
  # that will be uploaded. All these attributes will be validated by the service upon upload.
131
- def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
136
+ def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:, custom_metadata: {})
132
137
  raise NotImplementedError
133
138
  end
134
139
 
135
140
  # Returns a Hash of headers for +url_for_direct_upload+ requests.
136
- def headers_for_direct_upload(key, filename:, content_type:, content_length:, checksum:)
141
+ def headers_for_direct_upload(key, filename:, content_type:, content_length:, checksum:, custom_metadata: {})
137
142
  {}
138
143
  end
139
144
 
@@ -150,6 +155,9 @@ module ActiveStorage
150
155
  raise NotImplementedError
151
156
  end
152
157
 
158
+ def custom_metadata_headers(metadata)
159
+ raise NotImplementedError
160
+ end
153
161
 
154
162
  def instrument(operation, payload = {}, &block)
155
163
  ActiveSupport::Notifications.instrument(
@@ -15,297 +15,6 @@ module ActiveStorage
15
15
  private
16
16
  class UnsupportedImageProcessingMethod < StandardError; end
17
17
  class UnsupportedImageProcessingArgument < StandardError; end
18
- SUPPORTED_IMAGE_PROCESSING_METHODS = [
19
- "adaptive_blur",
20
- "adaptive_resize",
21
- "adaptive_sharpen",
22
- "adjoin",
23
- "affine",
24
- "alpha",
25
- "annotate",
26
- "antialias",
27
- "append",
28
- "apply",
29
- "attenuate",
30
- "authenticate",
31
- "auto_gamma",
32
- "auto_level",
33
- "auto_orient",
34
- "auto_threshold",
35
- "backdrop",
36
- "background",
37
- "bench",
38
- "bias",
39
- "bilateral_blur",
40
- "black_point_compensation",
41
- "black_threshold",
42
- "blend",
43
- "blue_primary",
44
- "blue_shift",
45
- "blur",
46
- "border",
47
- "bordercolor",
48
- "borderwidth",
49
- "brightness_contrast",
50
- "cache",
51
- "canny",
52
- "caption",
53
- "channel",
54
- "channel_fx",
55
- "charcoal",
56
- "chop",
57
- "clahe",
58
- "clamp",
59
- "clip",
60
- "clip_path",
61
- "clone",
62
- "clut",
63
- "coalesce",
64
- "colorize",
65
- "colormap",
66
- "color_matrix",
67
- "colors",
68
- "colorspace",
69
- "colourspace",
70
- "color_threshold",
71
- "combine",
72
- "combine_options",
73
- "comment",
74
- "compare",
75
- "complex",
76
- "compose",
77
- "composite",
78
- "compress",
79
- "connected_components",
80
- "contrast",
81
- "contrast_stretch",
82
- "convert",
83
- "convolve",
84
- "copy",
85
- "crop",
86
- "cycle",
87
- "deconstruct",
88
- "define",
89
- "delay",
90
- "delete",
91
- "density",
92
- "depth",
93
- "descend",
94
- "deskew",
95
- "despeckle",
96
- "direction",
97
- "displace",
98
- "dispose",
99
- "dissimilarity_threshold",
100
- "dissolve",
101
- "distort",
102
- "dither",
103
- "draw",
104
- "duplicate",
105
- "edge",
106
- "emboss",
107
- "encoding",
108
- "endian",
109
- "enhance",
110
- "equalize",
111
- "evaluate",
112
- "evaluate_sequence",
113
- "extent",
114
- "extract",
115
- "family",
116
- "features",
117
- "fft",
118
- "fill",
119
- "filter",
120
- "flatten",
121
- "flip",
122
- "floodfill",
123
- "flop",
124
- "font",
125
- "foreground",
126
- "format",
127
- "frame",
128
- "function",
129
- "fuzz",
130
- "fx",
131
- "gamma",
132
- "gaussian_blur",
133
- "geometry",
134
- "gravity",
135
- "grayscale",
136
- "green_primary",
137
- "hald_clut",
138
- "highlight_color",
139
- "hough_lines",
140
- "iconGeometry",
141
- "iconic",
142
- "identify",
143
- "ift",
144
- "illuminant",
145
- "immutable",
146
- "implode",
147
- "insert",
148
- "intensity",
149
- "intent",
150
- "interlace",
151
- "interline_spacing",
152
- "interpolate",
153
- "interpolative_resize",
154
- "interword_spacing",
155
- "kerning",
156
- "kmeans",
157
- "kuwahara",
158
- "label",
159
- "lat",
160
- "layers",
161
- "level",
162
- "level_colors",
163
- "limit",
164
- "limits",
165
- "linear_stretch",
166
- "linewidth",
167
- "liquid_rescale",
168
- "list",
169
- "loader",
170
- "log",
171
- "loop",
172
- "lowlight_color",
173
- "magnify",
174
- "map",
175
- "mattecolor",
176
- "median",
177
- "mean_shift",
178
- "metric",
179
- "mode",
180
- "modulate",
181
- "moments",
182
- "monitor",
183
- "monochrome",
184
- "morph",
185
- "morphology",
186
- "mosaic",
187
- "motion_blur",
188
- "name",
189
- "negate",
190
- "noise",
191
- "normalize",
192
- "opaque",
193
- "ordered_dither",
194
- "orient",
195
- "page",
196
- "paint",
197
- "pause",
198
- "perceptible",
199
- "ping",
200
- "pointsize",
201
- "polaroid",
202
- "poly",
203
- "posterize",
204
- "precision",
205
- "preview",
206
- "process",
207
- "quality",
208
- "quantize",
209
- "quiet",
210
- "radial_blur",
211
- "raise",
212
- "random_threshold",
213
- "range_threshold",
214
- "red_primary",
215
- "regard_warnings",
216
- "region",
217
- "remote",
218
- "render",
219
- "repage",
220
- "resample",
221
- "resize",
222
- "resize_to_fill",
223
- "resize_to_fit",
224
- "resize_to_limit",
225
- "resize_and_pad",
226
- "respect_parentheses",
227
- "reverse",
228
- "roll",
229
- "rotate",
230
- "sample",
231
- "sampling_factor",
232
- "saver",
233
- "scale",
234
- "scene",
235
- "screen",
236
- "seed",
237
- "segment",
238
- "selective_blur",
239
- "separate",
240
- "sepia_tone",
241
- "shade",
242
- "shadow",
243
- "shared_memory",
244
- "sharpen",
245
- "shave",
246
- "shear",
247
- "sigmoidal_contrast",
248
- "silent",
249
- "similarity_threshold",
250
- "size",
251
- "sketch",
252
- "smush",
253
- "snaps",
254
- "solarize",
255
- "sort_pixels",
256
- "sparse_color",
257
- "splice",
258
- "spread",
259
- "statistic",
260
- "stegano",
261
- "stereo",
262
- "storage_type",
263
- "stretch",
264
- "strip",
265
- "stroke",
266
- "strokewidth",
267
- "style",
268
- "subimage_search",
269
- "swap",
270
- "swirl",
271
- "synchronize",
272
- "taint",
273
- "text_font",
274
- "threshold",
275
- "thumbnail",
276
- "tile_offset",
277
- "tint",
278
- "title",
279
- "transform",
280
- "transparent",
281
- "transparent_color",
282
- "transpose",
283
- "transverse",
284
- "treedepth",
285
- "trim",
286
- "type",
287
- "undercolor",
288
- "unique_colors",
289
- "units",
290
- "unsharp",
291
- "update",
292
- "valid_image",
293
- "view",
294
- "vignette",
295
- "virtual_pixel",
296
- "visual",
297
- "watermark",
298
- "wave",
299
- "wavelet_denoise",
300
- "weight",
301
- "white_balance",
302
- "white_point",
303
- "white_threshold",
304
- "window",
305
- "window_group"
306
- ].concat(ActiveStorage.supported_image_processing_methods)
307
-
308
- UNSUPPORTED_IMAGE_PROCESSING_ARGUMENTS = ActiveStorage.unsupported_image_processing_arguments
309
18
 
310
19
  def process(file, format:)
311
20
  processor.
@@ -329,7 +38,7 @@ module ActiveStorage
329
38
  if name.to_s == "combine_options"
330
39
  raise ArgumentError, <<~ERROR.squish
331
40
  Active Storage's ImageProcessing transformer doesn't support :combine_options,
332
- as it always generates a single ImageMagick command.
41
+ as it always generates a single command.
333
42
  ERROR
334
43
  end
335
44
 
@@ -342,7 +51,7 @@ module ActiveStorage
342
51
  def validate_transformation(name, argument)
343
52
  method_name = name.to_s.tr("-", "_")
344
53
 
345
- unless SUPPORTED_IMAGE_PROCESSING_METHODS.any? { |method| method_name == method }
54
+ unless ActiveStorage.supported_image_processing_methods.any? { |method| method_name == method }
346
55
  raise UnsupportedImageProcessingMethod, <<~ERROR.squish
347
56
  One or more of the provided transformation methods is not supported.
348
57
  ERROR
@@ -360,7 +69,11 @@ module ActiveStorage
360
69
  end
361
70
 
362
71
  def validate_arg_string(argument)
363
- if UNSUPPORTED_IMAGE_PROCESSING_ARGUMENTS.any? { |bad_arg| argument.to_s.downcase.include?(bad_arg) }; raise UnsupportedImageProcessingArgument end
72
+ unsupported_arguments = ActiveStorage.unsupported_image_processing_arguments.any? do |bad_arg|
73
+ argument.to_s.downcase.include?(bad_arg)
74
+ end
75
+
76
+ raise UnsupportedImageProcessingArgument if unsupported_arguments
364
77
  end
365
78
 
366
79
  def validate_arg_array(argument)
@@ -31,7 +31,7 @@ module ActiveStorage
31
31
  private
32
32
  # Returns an open Tempfile containing a transformed image in the given +format+.
33
33
  # All subclasses implement this method.
34
- def process(file, format:) #:doc:
34
+ def process(file, format:) # :doc:
35
35
  raise NotImplementedError
36
36
  end
37
37
  end
@@ -3,7 +3,7 @@
3
3
  require_relative "gem_version"
4
4
 
5
5
  module ActiveStorage
6
- # Returns the version of the currently loaded ActiveStorage as a <tt>Gem::Version</tt>
6
+ # Returns the currently loaded version of Active Storage as a <tt>Gem::Version</tt>.
7
7
  def self.version
8
8
  gem_version
9
9
  end