activestorage 6.0.6.1 → 6.1.7.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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +215 -167
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +35 -3
  5. data/app/controllers/active_storage/base_controller.rb +11 -0
  6. data/app/controllers/active_storage/blobs/proxy_controller.rb +14 -0
  7. data/app/controllers/active_storage/{blobs_controller.rb → blobs/redirect_controller.rb} +2 -2
  8. data/app/controllers/active_storage/direct_uploads_controller.rb +1 -1
  9. data/app/controllers/active_storage/disk_controller.rb +8 -20
  10. data/app/controllers/active_storage/representations/base_controller.rb +14 -0
  11. data/app/controllers/active_storage/representations/proxy_controller.rb +13 -0
  12. data/app/controllers/active_storage/{representations_controller.rb → representations/redirect_controller.rb} +2 -4
  13. data/app/controllers/concerns/active_storage/file_server.rb +18 -0
  14. data/app/controllers/concerns/active_storage/set_blob.rb +1 -1
  15. data/app/controllers/concerns/active_storage/set_current.rb +2 -2
  16. data/app/controllers/concerns/active_storage/set_headers.rb +12 -0
  17. data/app/jobs/active_storage/mirror_job.rb +15 -0
  18. data/app/models/active_storage/attachment.rb +19 -11
  19. data/app/models/active_storage/blob/analyzable.rb +6 -2
  20. data/app/models/active_storage/blob/identifiable.rb +7 -6
  21. data/app/models/active_storage/blob/representable.rb +34 -4
  22. data/app/models/active_storage/blob.rb +122 -57
  23. data/app/models/active_storage/preview.rb +31 -10
  24. data/app/models/active_storage/record.rb +7 -0
  25. data/app/models/active_storage/variant.rb +31 -44
  26. data/app/models/active_storage/variant_record.rb +8 -0
  27. data/app/models/active_storage/variant_with_record.rb +54 -0
  28. data/app/models/active_storage/variation.rb +26 -21
  29. data/config/routes.rb +58 -8
  30. data/db/migrate/20170806125915_create_active_storage_tables.rb +30 -9
  31. data/db/update_migrate/20190112182829_add_service_name_to_active_storage_blobs.rb +21 -0
  32. data/db/update_migrate/20191206030411_create_active_storage_variant_records.rb +26 -0
  33. data/lib/active_storage/analyzer/image_analyzer.rb +3 -0
  34. data/lib/active_storage/analyzer/null_analyzer.rb +4 -0
  35. data/lib/active_storage/analyzer/video_analyzer.rb +14 -3
  36. data/lib/active_storage/analyzer.rb +6 -0
  37. data/lib/active_storage/attached/changes/create_many.rb +1 -0
  38. data/lib/active_storage/attached/changes/create_one.rb +17 -4
  39. data/lib/active_storage/attached/many.rb +4 -3
  40. data/lib/active_storage/attached/model.rb +67 -14
  41. data/lib/active_storage/attached/one.rb +4 -3
  42. data/lib/active_storage/engine.rb +41 -43
  43. data/lib/active_storage/errors.rb +3 -0
  44. data/lib/active_storage/gem_version.rb +3 -3
  45. data/lib/active_storage/log_subscriber.rb +6 -0
  46. data/lib/active_storage/previewer/mupdf_previewer.rb +3 -3
  47. data/lib/active_storage/previewer/poppler_pdf_previewer.rb +2 -2
  48. data/lib/active_storage/previewer/video_previewer.rb +5 -3
  49. data/lib/active_storage/previewer.rb +13 -3
  50. data/lib/active_storage/service/azure_storage_service.rb +40 -35
  51. data/lib/active_storage/service/configurator.rb +3 -1
  52. data/lib/active_storage/service/disk_service.rb +36 -31
  53. data/lib/active_storage/service/gcs_service.rb +18 -16
  54. data/lib/active_storage/service/mirror_service.rb +31 -7
  55. data/lib/active_storage/service/registry.rb +32 -0
  56. data/lib/active_storage/service/s3_service.rb +51 -23
  57. data/lib/active_storage/service.rb +35 -7
  58. data/lib/active_storage/transformers/image_processing_transformer.rb +21 -308
  59. data/lib/active_storage/transformers/transformer.rb +0 -3
  60. data/lib/active_storage.rb +301 -7
  61. data/lib/tasks/activestorage.rake +5 -1
  62. metadata +53 -16
  63. data/db/update_migrate/20180723000244_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.rb +0 -9
  64. data/lib/active_storage/downloading.rb +0 -47
  65. data/lib/active_storage/transformers/mini_magick_transformer.rb +0 -38
@@ -41,6 +41,7 @@ module ActiveStorage
41
41
  class Service
42
42
  extend ActiveSupport::Autoload
43
43
  autoload :Configurator
44
+ attr_accessor :name
44
45
 
45
46
  class << self
46
47
  # Configure an Active Storage service by name from a set of configurations,
@@ -56,8 +57,10 @@ module ActiveStorage
56
57
  # Passes the configurator and all of the service's config as keyword args.
57
58
  #
58
59
  # See MirrorService for an example.
59
- def build(configurator:, service: nil, **service_config) #:nodoc:
60
- new(**service_config)
60
+ def build(configurator:, name:, service: nil, **service_config) #:nodoc:
61
+ new(**service_config).tap do |service_instance|
62
+ service_instance.name = name
63
+ end
61
64
  end
62
65
  end
63
66
 
@@ -102,11 +105,23 @@ module ActiveStorage
102
105
  raise NotImplementedError
103
106
  end
104
107
 
105
- # Returns a signed, temporary URL for the file at the +key+. The URL will be valid for the amount
106
- # of seconds specified in +expires_in+. You must also provide the +disposition+ (+:inline+ or +:attachment+),
107
- # +filename+, and +content_type+ that you wish the file to be served with on request.
108
- def url(key, expires_in:, disposition:, filename:, content_type:)
109
- raise NotImplementedError
108
+ # Returns the URL for the file at the +key+. This returns a permanent URL for public files, and returns a
109
+ # short-lived URL for private files. For private files you can provide the +disposition+ (+:inline+ or +:attachment+),
110
+ # +filename+, and +content_type+ that you wish the file to be served with on request. Additionally, you can also provide
111
+ # the amount of seconds the URL will be valid for, specified in +expires_in+.
112
+ def url(key, **options)
113
+ instrument :url, key: key do |payload|
114
+ generated_url =
115
+ if public?
116
+ public_url(key, **options)
117
+ else
118
+ private_url(key, **options)
119
+ end
120
+
121
+ payload[:url] = generated_url
122
+
123
+ generated_url
124
+ end
110
125
  end
111
126
 
112
127
  # Returns a signed, temporary URL that a direct upload file can be PUT to on the +key+.
@@ -122,7 +137,20 @@ module ActiveStorage
122
137
  {}
123
138
  end
124
139
 
140
+ def public?
141
+ @public
142
+ end
143
+
125
144
  private
145
+ def private_url(key, expires_in:, filename:, disposition:, content_type:, **)
146
+ raise NotImplementedError
147
+ end
148
+
149
+ def public_url(key, **)
150
+ raise NotImplementedError
151
+ end
152
+
153
+
126
154
  def instrument(operation, payload = {}, &block)
127
155
  ActiveSupport::Notifications.instrument(
128
156
  "service_#{operation}.active_storage",
@@ -1,6 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "image_processing"
3
+ begin
4
+ require "image_processing"
5
+ rescue LoadError
6
+ raise LoadError, <<~ERROR.squish
7
+ Generating image variants require the image_processing gem.
8
+ Please add `gem 'image_processing', '~> 1.2'` to your Gemfile.
9
+ ERROR
10
+ end
4
11
 
5
12
  module ActiveStorage
6
13
  module Transformers
@@ -8,297 +15,6 @@ module ActiveStorage
8
15
  private
9
16
  class UnsupportedImageProcessingMethod < StandardError; end
10
17
  class UnsupportedImageProcessingArgument < StandardError; end
11
- SUPPORTED_IMAGE_PROCESSING_METHODS = [
12
- "adaptive_blur",
13
- "adaptive_resize",
14
- "adaptive_sharpen",
15
- "adjoin",
16
- "affine",
17
- "alpha",
18
- "annotate",
19
- "antialias",
20
- "append",
21
- "apply",
22
- "attenuate",
23
- "authenticate",
24
- "auto_gamma",
25
- "auto_level",
26
- "auto_orient",
27
- "auto_threshold",
28
- "backdrop",
29
- "background",
30
- "bench",
31
- "bias",
32
- "bilateral_blur",
33
- "black_point_compensation",
34
- "black_threshold",
35
- "blend",
36
- "blue_primary",
37
- "blue_shift",
38
- "blur",
39
- "border",
40
- "bordercolor",
41
- "borderwidth",
42
- "brightness_contrast",
43
- "cache",
44
- "canny",
45
- "caption",
46
- "channel",
47
- "channel_fx",
48
- "charcoal",
49
- "chop",
50
- "clahe",
51
- "clamp",
52
- "clip",
53
- "clip_path",
54
- "clone",
55
- "clut",
56
- "coalesce",
57
- "colorize",
58
- "colormap",
59
- "color_matrix",
60
- "colors",
61
- "colorspace",
62
- "colourspace",
63
- "color_threshold",
64
- "combine",
65
- "combine_options",
66
- "comment",
67
- "compare",
68
- "complex",
69
- "compose",
70
- "composite",
71
- "compress",
72
- "connected_components",
73
- "contrast",
74
- "contrast_stretch",
75
- "convert",
76
- "convolve",
77
- "copy",
78
- "crop",
79
- "cycle",
80
- "deconstruct",
81
- "define",
82
- "delay",
83
- "delete",
84
- "density",
85
- "depth",
86
- "descend",
87
- "deskew",
88
- "despeckle",
89
- "direction",
90
- "displace",
91
- "dispose",
92
- "dissimilarity_threshold",
93
- "dissolve",
94
- "distort",
95
- "dither",
96
- "draw",
97
- "duplicate",
98
- "edge",
99
- "emboss",
100
- "encoding",
101
- "endian",
102
- "enhance",
103
- "equalize",
104
- "evaluate",
105
- "evaluate_sequence",
106
- "extent",
107
- "extract",
108
- "family",
109
- "features",
110
- "fft",
111
- "fill",
112
- "filter",
113
- "flatten",
114
- "flip",
115
- "floodfill",
116
- "flop",
117
- "font",
118
- "foreground",
119
- "format",
120
- "frame",
121
- "function",
122
- "fuzz",
123
- "fx",
124
- "gamma",
125
- "gaussian_blur",
126
- "geometry",
127
- "gravity",
128
- "grayscale",
129
- "green_primary",
130
- "hald_clut",
131
- "highlight_color",
132
- "hough_lines",
133
- "iconGeometry",
134
- "iconic",
135
- "identify",
136
- "ift",
137
- "illuminant",
138
- "immutable",
139
- "implode",
140
- "insert",
141
- "intensity",
142
- "intent",
143
- "interlace",
144
- "interline_spacing",
145
- "interpolate",
146
- "interpolative_resize",
147
- "interword_spacing",
148
- "kerning",
149
- "kmeans",
150
- "kuwahara",
151
- "label",
152
- "lat",
153
- "layers",
154
- "level",
155
- "level_colors",
156
- "limit",
157
- "limits",
158
- "linear_stretch",
159
- "linewidth",
160
- "liquid_rescale",
161
- "list",
162
- "loader",
163
- "log",
164
- "loop",
165
- "lowlight_color",
166
- "magnify",
167
- "map",
168
- "mattecolor",
169
- "median",
170
- "mean_shift",
171
- "metric",
172
- "mode",
173
- "modulate",
174
- "moments",
175
- "monitor",
176
- "monochrome",
177
- "morph",
178
- "morphology",
179
- "mosaic",
180
- "motion_blur",
181
- "name",
182
- "negate",
183
- "noise",
184
- "normalize",
185
- "opaque",
186
- "ordered_dither",
187
- "orient",
188
- "page",
189
- "paint",
190
- "pause",
191
- "perceptible",
192
- "ping",
193
- "pointsize",
194
- "polaroid",
195
- "poly",
196
- "posterize",
197
- "precision",
198
- "preview",
199
- "process",
200
- "quality",
201
- "quantize",
202
- "quiet",
203
- "radial_blur",
204
- "raise",
205
- "random_threshold",
206
- "range_threshold",
207
- "red_primary",
208
- "regard_warnings",
209
- "region",
210
- "remote",
211
- "render",
212
- "repage",
213
- "resample",
214
- "resize",
215
- "resize_to_fill",
216
- "resize_to_fit",
217
- "resize_to_limit",
218
- "resize_and_pad",
219
- "respect_parentheses",
220
- "reverse",
221
- "roll",
222
- "rotate",
223
- "sample",
224
- "sampling_factor",
225
- "saver",
226
- "scale",
227
- "scene",
228
- "screen",
229
- "seed",
230
- "segment",
231
- "selective_blur",
232
- "separate",
233
- "sepia_tone",
234
- "shade",
235
- "shadow",
236
- "shared_memory",
237
- "sharpen",
238
- "shave",
239
- "shear",
240
- "sigmoidal_contrast",
241
- "silent",
242
- "similarity_threshold",
243
- "size",
244
- "sketch",
245
- "smush",
246
- "snaps",
247
- "solarize",
248
- "sort_pixels",
249
- "sparse_color",
250
- "splice",
251
- "spread",
252
- "statistic",
253
- "stegano",
254
- "stereo",
255
- "storage_type",
256
- "stretch",
257
- "strip",
258
- "stroke",
259
- "strokewidth",
260
- "style",
261
- "subimage_search",
262
- "swap",
263
- "swirl",
264
- "synchronize",
265
- "taint",
266
- "text_font",
267
- "threshold",
268
- "thumbnail",
269
- "tile_offset",
270
- "tint",
271
- "title",
272
- "transform",
273
- "transparent",
274
- "transparent_color",
275
- "transpose",
276
- "transverse",
277
- "treedepth",
278
- "trim",
279
- "type",
280
- "undercolor",
281
- "unique_colors",
282
- "units",
283
- "unsharp",
284
- "update",
285
- "valid_image",
286
- "view",
287
- "vignette",
288
- "virtual_pixel",
289
- "visual",
290
- "watermark",
291
- "wave",
292
- "wavelet_denoise",
293
- "weight",
294
- "white_balance",
295
- "white_point",
296
- "white_threshold",
297
- "window",
298
- "window_group"
299
- ].concat(ActiveStorage.supported_image_processing_methods)
300
-
301
- UNSUPPORTED_IMAGE_PROCESSING_ARGUMENTS = ActiveStorage.unsupported_image_processing_arguments
302
18
 
303
19
  def process(file, format:)
304
20
  processor.
@@ -316,33 +32,26 @@ module ActiveStorage
316
32
  def operations
317
33
  transformations.each_with_object([]) do |(name, argument), list|
318
34
  if ActiveStorage.variant_processor == :mini_magick
319
- if name.to_s == "combine_options"
320
- argument.each do |subtransformation_name, subtransformation_argument|
321
- validate_transformation(subtransformation_name, subtransformation_argument)
322
- end
323
- else
324
- validate_transformation(name, argument)
325
- end
35
+ validate_transformation(name, argument)
326
36
  end
327
37
 
328
38
  if name.to_s == "combine_options"
329
- ActiveSupport::Deprecation.warn <<~WARNING.squish
39
+ raise ArgumentError, <<~ERROR.squish
330
40
  Active Storage's ImageProcessing transformer doesn't support :combine_options,
331
- as it always generates a single ImageMagick command. Passing :combine_options will
332
- not be supported in Rails 6.1.
333
- WARNING
41
+ as it always generates a single ImageMagick command.
42
+ ERROR
43
+ end
334
44
 
335
- list.concat argument.keep_if { |key, value| value.present? }.to_a
336
- elsif argument.present?
45
+ if argument.present?
337
46
  list << [ name, argument ]
338
47
  end
339
48
  end
340
49
  end
341
50
 
342
51
  def validate_transformation(name, argument)
343
- method_name = name.to_s.gsub("-","_")
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)
@@ -8,9 +8,6 @@ module ActiveStorage
8
8
  #
9
9
  # * ActiveStorage::Transformers::ImageProcessingTransformer:
10
10
  # backed by ImageProcessing, a common interface for MiniMagick and ruby-vips
11
- #
12
- # * ActiveStorage::Transformers::MiniMagickTransformer:
13
- # backed by MiniMagick, a wrapper around the ImageMagick CLI
14
11
  class Transformer
15
12
  attr_reader :transformations
16
13