activestorage 5.2.4 → 6.0.2.1

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +159 -60
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +9 -6
  5. data/app/assets/javascripts/activestorage.js +4 -1
  6. data/app/controllers/active_storage/base_controller.rb +3 -5
  7. data/app/controllers/active_storage/blobs_controller.rb +1 -1
  8. data/app/controllers/active_storage/disk_controller.rb +5 -2
  9. data/app/controllers/active_storage/representations_controller.rb +1 -1
  10. data/app/controllers/concerns/active_storage/set_current.rb +15 -0
  11. data/app/javascript/activestorage/blob_record.js +6 -1
  12. data/app/jobs/active_storage/analyze_job.rb +5 -0
  13. data/app/jobs/active_storage/base_job.rb +0 -1
  14. data/app/jobs/active_storage/purge_job.rb +3 -0
  15. data/app/models/active_storage/attachment.rb +20 -9
  16. data/app/models/active_storage/blob.rb +89 -34
  17. data/app/models/active_storage/blob/representable.rb +5 -5
  18. data/app/models/active_storage/filename.rb +0 -6
  19. data/app/models/active_storage/preview.rb +3 -3
  20. data/app/models/active_storage/variant.rb +51 -52
  21. data/app/models/active_storage/variation.rb +24 -33
  22. data/config/routes.rb +13 -12
  23. data/db/update_migrate/20180723000244_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.rb +9 -0
  24. data/lib/active_storage.rb +26 -6
  25. data/lib/active_storage/analyzer.rb +9 -4
  26. data/lib/active_storage/analyzer/image_analyzer.rb +11 -4
  27. data/lib/active_storage/analyzer/video_analyzer.rb +3 -5
  28. data/lib/active_storage/attached.rb +7 -22
  29. data/lib/active_storage/attached/changes.rb +16 -0
  30. data/lib/active_storage/attached/changes/create_many.rb +46 -0
  31. data/lib/active_storage/attached/changes/create_one.rb +69 -0
  32. data/lib/active_storage/attached/changes/create_one_of_many.rb +10 -0
  33. data/lib/active_storage/attached/changes/delete_many.rb +27 -0
  34. data/lib/active_storage/attached/changes/delete_one.rb +19 -0
  35. data/lib/active_storage/attached/many.rb +16 -10
  36. data/lib/active_storage/attached/model.rb +147 -0
  37. data/lib/active_storage/attached/one.rb +16 -19
  38. data/lib/active_storage/downloader.rb +43 -0
  39. data/lib/active_storage/downloading.rb +8 -0
  40. data/lib/active_storage/engine.rb +43 -6
  41. data/lib/active_storage/errors.rb +22 -3
  42. data/lib/active_storage/gem_version.rb +4 -4
  43. data/lib/active_storage/previewer.rb +21 -11
  44. data/lib/active_storage/previewer/poppler_pdf_previewer.rb +2 -2
  45. data/lib/active_storage/previewer/video_previewer.rb +2 -3
  46. data/lib/active_storage/reflection.rb +64 -0
  47. data/lib/active_storage/service.rb +9 -6
  48. data/lib/active_storage/service/azure_storage_service.rb +30 -14
  49. data/lib/active_storage/service/configurator.rb +3 -1
  50. data/lib/active_storage/service/disk_service.rb +19 -11
  51. data/lib/active_storage/service/gcs_service.rb +49 -47
  52. data/lib/active_storage/service/s3_service.rb +10 -6
  53. data/lib/active_storage/transformers/image_processing_transformer.rb +39 -0
  54. data/lib/active_storage/transformers/mini_magick_transformer.rb +38 -0
  55. data/lib/active_storage/transformers/transformer.rb +42 -0
  56. data/lib/tasks/activestorage.rake +7 -0
  57. metadata +41 -12
  58. data/app/models/active_storage/filename/parameters.rb +0 -36
  59. data/lib/active_storage/attached/macros.rb +0 -110
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b72c9420f7235052fa72e9f13c9df4fb72ae3a36424be0359bb01514cd08a304
4
- data.tar.gz: b56ae498f785ac781dcf4d81f502f6eba480838abfb6abd2f0fa53266c1e8b08
3
+ metadata.gz: 1e078ef58663acbb9d7977eca0bd286bd309ff14767b95c3680ef8d454bcc456
4
+ data.tar.gz: 36fdbdc4ddc37b685902f7f29ad6e4887884e484a1169728c2cae20bf179acb4
5
5
  SHA512:
6
- metadata.gz: 7e90d469b456d42ff592f3be78dae4ff2eb778a48e55678f961b768429f316a194154e86b997da5d224ddca9b708c83ef134649fb6bedc35a94c668d63ed8308
7
- data.tar.gz: bba66b4b994a4e86f5dcfdc43ae80908d3d223f29c6cf5b0c9f02754810c3c4d6dc06563b859aa657a83b23b8f15638ac82bf039ee0f873a4d36ba37b54d81cd
6
+ metadata.gz: e469cddfd1da438825abf7079bf62582d0d52f9da6ffa7296e0b7f9a96c1195276167fb61ed947b5fee04fb838f4d2b1c5001eba6e1305bd6ef49e73abcfb340
7
+ data.tar.gz: 0ba9772c58c6831aa37627e641e4b90a7eff8c240e1bc04e47d82c52829acf744128218af11e1541371f5192c25d023fccdfce86f06690eb382689e610c53682
@@ -1,122 +1,221 @@
1
- ## Rails 5.2.4 (November 27, 2019) ##
1
+ ## Rails 6.0.2.1 (December 18, 2019) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 5.2.3 (March 27, 2019) ##
6
+ ## Rails 6.0.2 (December 13, 2019) ##
7
7
 
8
8
  * No changes.
9
9
 
10
10
 
11
- ## Rails 5.2.2.1 (March 11, 2019) ##
11
+ ## Rails 6.0.1 (November 5, 2019) ##
12
+
13
+ * `ActiveStorage::AnalyzeJob`s are discarded on `ActiveRecord::RecordNotFound` errors.
14
+
15
+ *George Claghorn*
16
+
17
+ * Blobs are recorded in the database before being uploaded to the service.
18
+ This fixes that generated blob keys could silently collide, leading to
19
+ data loss.
20
+
21
+ *Julik Tarkhanov*
22
+
23
+
24
+ ## Rails 6.0.0 (August 16, 2019) ##
12
25
 
13
26
  * No changes.
14
27
 
15
28
 
16
- ## Rails 5.2.2 (December 04, 2018) ##
29
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
17
30
 
18
- * Support multiple submit buttons in Active Storage forms.
31
+ * No changes.
19
32
 
20
- *Chrıs Seelus*
21
33
 
22
- * Fix `ArgumentError` when uploading to amazon s3
34
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
23
35
 
24
- *Hiroki Sanpei*
36
+ * Don't raise when analyzing an image whose type is unsupported by ImageMagick.
25
37
 
26
- * Add a foreign-key constraint to the `active_storage_attachments` table for blobs.
38
+ Fixes #36065.
27
39
 
28
- *George Claghorn*
40
+ *Guilherme Mansur*
29
41
 
30
- * Discard `ActiveStorage::PurgeJobs` for missing blobs.
42
+ * Permit generating variants of BMP images.
31
43
 
32
- *George Claghorn*
44
+ *Younes Serraj*
33
45
 
34
- * Fix uploading Tempfiles to Azure Storage.
35
46
 
36
- *George Claghorn*
47
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
48
+
49
+ * No changes.
37
50
 
38
51
 
39
- ## Rails 5.2.1.1 (November 27, 2018) ##
52
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
40
53
 
41
- * Prevent content type and disposition bypass in storage service URLs.
54
+ * No changes.
42
55
 
43
- Fix CVE-2018-16477.
44
56
 
45
- *Rosa Gutierrez*
57
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
46
58
 
59
+ * [Rename npm package](https://github.com/rails/rails/pull/34905) from
60
+ [`activestorage`](https://www.npmjs.com/package/activestorage) to
61
+ [`@rails/activestorage`](https://www.npmjs.com/package/@rails/activestorage).
47
62
 
48
- ## Rails 5.2.1 (August 07, 2018) ##
63
+ *Javan Makhmali*
49
64
 
50
- * Fix direct upload with zero-byte files.
65
+ * Replace `config.active_storage.queue` with two options that indicate which
66
+ queues analysis and purge jobs should use, respectively:
67
+
68
+ * `config.active_storage.queues.analysis`
69
+ * `config.active_storage.queues.purge`
70
+
71
+ `config.active_storage.queue` is preferred over the new options when it's
72
+ set, but it is deprecated and will be removed in Rails 6.1.
51
73
 
52
74
  *George Claghorn*
53
75
 
54
- * Exclude JSON root from `active_storage/direct_uploads#create` response.
76
+ * Permit generating variants of TIFF images.
55
77
 
56
- *Javan Makhmali*
78
+ *Luciano Sousa*
79
+
80
+ * Use base36 (all lowercase) for all new Blob keys to prevent
81
+ collisions and undefined behavior with case-insensitive filesystems and
82
+ database indices.
83
+
84
+ *Julik Tarkhanov*
57
85
 
86
+ * It doesn’t include an `X-CSRF-Token` header if a meta tag is not found on
87
+ the page. It previously included one with a value of `undefined`.
58
88
 
59
- ## Rails 5.2.0 (April 09, 2018) ##
89
+ *Cameron Bothner*
60
90
 
61
- * Allow full use of the AWS S3 SDK options for authentication. If an
62
- explicit AWS key pair and/or region is not provided in `storage.yml`,
63
- attempt to use environment variables, shared credentials, or IAM
64
- (instance or task) role credentials. Order of precedence is determined
65
- by the [AWS SDK](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html).
91
+ * Fix `ArgumentError` when uploading to amazon s3
92
+
93
+ *Hiroki Sanpei*
94
+
95
+ * Add progressive JPG to default list of variable content types
96
+
97
+ *Maurice Kühlborn*
98
+
99
+ * Add `ActiveStorage.routes_prefix` for configuring generated routes.
100
+
101
+ *Chris Bisnett*
102
+
103
+ * `ActiveStorage::Service::AzureStorageService` only handles specifically
104
+ relevant types of `Azure::Core::Http::HTTPError`. It previously obscured
105
+ other types of `HTTPError`, which is the azure-storage gem’s catch-all
106
+ exception class.
107
+
108
+ *Cameron Bothner*
109
+
110
+ * `ActiveStorage::DiskController#show` generates a 404 Not Found response when
111
+ the requested file is missing from the disk service. It previously raised
112
+ `Errno::ENOENT`.
113
+
114
+ *Cameron Bothner*
66
115
 
67
- *Brian Knight*
116
+ * `ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
117
+ `ActiveStorage::FileNotFoundError` when the corresponding file is missing
118
+ from the storage service. Services translate service-specific missing object
119
+ exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service and
120
+ `Errno::ENOENT` for the disk service) into
121
+ `ActiveStorage::FileNotFoundError`.
68
122
 
69
- * Remove path config option from Azure service.
123
+ *Cameron Bothner*
70
124
 
71
- The Active Storage service for Azure Storage has an option called `path`
72
- that is ambiguous in meaning. It needs to be set to the primary blob
73
- storage endpoint but that can be determined from the blobs client anyway.
125
+ * Added the `ActiveStorage::SetCurrent` concern for custom Active Storage
126
+ controllers that can't inherit from `ActiveStorage::BaseController`.
74
127
 
75
- To simplify the configuration, we've removed the `path` option and
76
- now get the endpoint from the blobs client instead.
128
+ *George Claghorn*
129
+
130
+ * Active Storage error classes like `ActiveStorage::IntegrityError` and
131
+ `ActiveStorage::UnrepresentableError` now inherit from `ActiveStorage::Error`
132
+ instead of `StandardError`. This permits rescuing `ActiveStorage::Error` to
133
+ handle all Active Storage errors.
134
+
135
+ *Andrei Makarov*, *George Claghorn*
77
136
 
78
- Closes #32225.
137
+ * Uploaded files assigned to a record are persisted to storage when the record
138
+ is saved instead of immediately.
79
139
 
80
- *Andrew White*
140
+ In Rails 5.2, the following causes an uploaded file in `params[:avatar]` to
141
+ be stored:
81
142
 
82
- * Generate root-relative paths in disk service URL methods.
143
+ ```ruby
144
+ @user.avatar = params[:avatar]
145
+ ```
83
146
 
84
- Obviate the disk service's `:host` configuration option.
147
+ In Rails 6, the uploaded file is stored when `@user` is successfully saved.
85
148
 
86
149
  *George Claghorn*
87
150
 
88
- * Add source code to published npm package.
151
+ * Add the ability to reflect on defined attachments using the existing
152
+ ActiveRecord reflection mechanism.
153
+
154
+ *Kevin Deisz*
155
+
156
+ * Variant arguments of `false` or `nil` will no longer be passed to the
157
+ processor. For example, the following will not have the monochrome
158
+ variation applied:
159
+
160
+ ```ruby
161
+ avatar.variant(monochrome: false)
162
+ ```
163
+
164
+ *Jacob Smith*
165
+
166
+ * Generated attachment getter and setter methods are created
167
+ within the model's `GeneratedAssociationMethods` module to
168
+ allow overriding and composition using `super`.
169
+
170
+ *Josh Susser*, *Jamon Douglas*
171
+
172
+ * Add `ActiveStorage::Blob#open`, which downloads a blob to a tempfile on disk
173
+ and yields the tempfile. Deprecate `ActiveStorage::Downloading`.
174
+
175
+ *David Robertson*, *George Claghorn*
89
176
 
90
- This allows activestorage users to depend on the javascript source code
91
- rather than the compiled code, which can produce smaller javascript bundles.
177
+ * Pass in `identify: false` as an argument when providing a `content_type` for
178
+ `ActiveStorage::Attached::{One,Many}#attach` to bypass automatic content
179
+ type inference. For example:
92
180
 
93
- *Richard Macklin*
181
+ ```ruby
182
+ @message.image.attach(
183
+ io: File.open('/path/to/file'),
184
+ filename: 'file.pdf',
185
+ content_type: 'application/pdf',
186
+ identify: false
187
+ )
188
+ ```
94
189
 
95
- * Preserve display aspect ratio when extracting width and height from videos
96
- with rectangular samples in `ActiveStorage::Analyzer::VideoAnalyzer`.
190
+ *Ryan Davidson*
97
191
 
98
- When a video contains a display aspect ratio, emit it in metadata as
99
- `:display_aspect_ratio` rather than the ambiguous `:aspect_ratio`. Compute
100
- its height by scaling its encoded frame width according to the DAR.
192
+ * The Google Cloud Storage service properly supports streaming downloads.
193
+ It now requires version 1.11 or newer of the google-cloud-storage gem.
101
194
 
102
195
  *George Claghorn*
103
196
 
104
- * Use `after_destroy_commit` instead of `before_destroy` for purging
105
- attachments when a record is destroyed.
197
+ * Use the [ImageProcessing](https://github.com/janko-m/image_processing) gem
198
+ for Active Storage variants, and deprecate the MiniMagick backend.
106
199
 
107
- *Hiroki Zenigami*
200
+ This means that variants are now automatically oriented if the original
201
+ image was rotated. Also, in addition to the existing ImageMagick
202
+ operations, variants can now use `:resize_to_fit`, `:resize_to_fill`, and
203
+ other ImageProcessing macros. These are now recommended over raw `:resize`,
204
+ as they also sharpen the thumbnail after resizing.
108
205
 
109
- * Force `:attachment` disposition for specific, configurable content types.
110
- This mitigates possible security issues such as XSS or phishing when
111
- serving them inline. A list of such content types is included by default,
112
- and can be configured via `content_types_to_serve_as_binary`.
206
+ The ImageProcessing gem also comes with a backend implemented on
207
+ [libvips](http://jcupitt.github.io/libvips/), an alternative to
208
+ ImageMagick which has significantly better performance than
209
+ ImageMagick in most cases, both in terms of speed and memory usage. In
210
+ Active Storage it's now possible to switch to the libvips backend by
211
+ changing `Rails.application.config.active_storage.variant_processor` to
212
+ `:vips`.
113
213
 
114
- *Rosa Gutierrez*
214
+ *Janko Marohnić*
115
215
 
116
- * Fix the gem adding the migrations files to the package.
216
+ * Rails 6 requires Ruby 2.5.0 or newer.
117
217
 
118
- *Yuji Yaginuma*
218
+ *Jeremy Daer*, *Kasper Timm Hansen*
119
219
 
120
- * Added to Rails.
121
220
 
122
- *DHH*
221
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activestorage/CHANGELOG.md) for previous changes.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017-2018 David Heinemeier Hansson, Basecamp
1
+ Copyright (c) 2017-2019 David Heinemeier Hansson, Basecamp
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -4,11 +4,13 @@ Active Storage makes it simple to upload and reference files in cloud services l
4
4
 
5
5
  Files can be uploaded from the server to the cloud or directly from the client to the cloud.
6
6
 
7
- Image files can furthermore be transformed using on-demand variants for quality, aspect ratio, size, or any other [MiniMagick](https://github.com/minimagick/minimagick) supported transformation.
7
+ Image files can furthermore be transformed using on-demand variants for quality, aspect ratio, size, or any other [MiniMagick](https://github.com/minimagick/minimagick) or [Vips](https://www.rubydoc.info/gems/ruby-vips/Vips/Image) supported transformation.
8
+
9
+ You can read more about Active Storage in the [Active Storage Overview](https://edgeguides.rubyonrails.org/active_storage_overview.html) guide.
8
10
 
9
11
  ## Compared to other storage solutions
10
12
 
11
- A key difference to how Active Storage works compared to other attachment solutions in Rails is through the use of built-in [Blob](https://github.com/rails/rails/blob/5-2-stable/activestorage/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/rails/blob/5-2-stable/activestorage/app/models/active_storage/attachment.rb) models (backed by Active Record). This means existing application models do not need to be modified with additional columns to associate with files. Active Storage uses polymorphic associations via the `Attachment` join model, which then connects to the actual `Blob`.
13
+ A key difference to how Active Storage works compared to other attachment solutions in Rails is through the use of built-in [Blob](https://github.com/rails/rails/blob/master/activestorage/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/rails/blob/master/activestorage/app/models/active_storage/attachment.rb) models (backed by Active Record). This means existing application models do not need to be modified with additional columns to associate with files. Active Storage uses polymorphic associations via the `Attachment` join model, which then connects to the actual `Blob`.
12
14
 
13
15
  `Blob` models store attachment metadata (filename, content-type, etc.), and their identifier key in the storage service. Blob models do not store the actual binary data. They are intended to be immutable in spirit. One file, one blob. You can associate the same blob with multiple application models as well. And if you want to do transformations of a given `Blob`, the idea is that you'll simply create a new one, rather than attempt to mutate the existing one (though of course you can delete the previous version later if you don't need it).
14
16
 
@@ -16,6 +18,8 @@ A key difference to how Active Storage works compared to other attachment soluti
16
18
 
17
19
  Run `rails active_storage:install` to copy over active_storage migrations.
18
20
 
21
+ NOTE: If the task cannot be found, verify that `require "active_storage/engine"` is present in `config/application.rb`.
22
+
19
23
  ## Examples
20
24
 
21
25
  One attachment:
@@ -99,7 +103,7 @@ Variation of image attachment:
99
103
 
100
104
  ```erb
101
105
  <%# Hitting the variant URL will lazy transform the original blob and then redirect to its new service location %>
102
- <%= image_tag user.avatar.variant(resize: "100x100") %>
106
+ <%= image_tag user.avatar.variant(resize_to_limit: [100, 100]) %>
103
107
  ```
104
108
 
105
109
  ## Direct uploads
@@ -116,8 +120,7 @@ Active Storage, with its included JavaScript library, supports uploading directl
116
120
  ```
117
121
  Using the npm package:
118
122
  ```js
119
- import * as ActiveStorage from "activestorage"
120
- ActiveStorage.start()
123
+ require("@rails/activestorage").start()
121
124
  ```
122
125
  2. Annotate file inputs with the direct upload URL.
123
126
 
@@ -148,7 +151,7 @@ Active Storage is released under the [MIT License](https://opensource.org/licens
148
151
 
149
152
  API documentation is at:
150
153
 
151
- * http://api.rubyonrails.org
154
+ * https://api.rubyonrails.org
152
155
 
153
156
  Bug reports for the Ruby on Rails project can be filed here:
154
157
 
@@ -560,7 +560,10 @@
560
560
  this.xhr.setRequestHeader("Content-Type", "application/json");
561
561
  this.xhr.setRequestHeader("Accept", "application/json");
562
562
  this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
563
- this.xhr.setRequestHeader("X-CSRF-Token", getMetaValue("csrf-token"));
563
+ var csrfToken = getMetaValue("csrf-token");
564
+ if (csrfToken != undefined) {
565
+ this.xhr.setRequestHeader("X-CSRF-Token", csrfToken);
566
+ }
564
567
  this.xhr.addEventListener("load", function(event) {
565
568
  return _this.requestDidLoad(event);
566
569
  });
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # The base controller for all ActiveStorage controllers.
3
+ # The base class for all Active Storage controllers.
4
4
  class ActiveStorage::BaseController < ActionController::Base
5
- protect_from_forgery with: :exception
5
+ include ActiveStorage::SetCurrent
6
6
 
7
- before_action do
8
- ActiveStorage::Current.host = request.base_url
9
- end
7
+ protect_from_forgery with: :exception
10
8
  end
@@ -8,7 +8,7 @@ class ActiveStorage::BlobsController < ActiveStorage::BaseController
8
8
  include ActiveStorage::SetBlob
9
9
 
10
10
  def show
11
- expires_in ActiveStorage::Blob.service.url_expires_in
11
+ expires_in ActiveStorage.service_urls_expire_in
12
12
  redirect_to @blob.service_url(disposition: params[:disposition])
13
13
  end
14
14
  end
@@ -3,7 +3,7 @@
3
3
  # Serves files stored with the disk service in the same way that the cloud services do.
4
4
  # This means using expiring, signed URLs that are meant for immediate access, not permanent linking.
5
5
  # Always go through the BlobsController, or your own authenticated controller, rather than directly
6
- # to the service url.
6
+ # to the service URL.
7
7
  class ActiveStorage::DiskController < ActiveStorage::BaseController
8
8
  skip_forgery_protection
9
9
 
@@ -13,16 +13,19 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
13
13
  else
14
14
  head :not_found
15
15
  end
16
+ rescue Errno::ENOENT
17
+ head :not_found
16
18
  end
17
19
 
18
20
  def update
19
21
  if token = decode_verified_token
20
22
  if acceptable_content?(token)
21
23
  disk_service.upload token[:key], request.body, checksum: token[:checksum]
22
- head :no_content
23
24
  else
24
25
  head :unprocessable_entity
25
26
  end
27
+ else
28
+ head :not_found
26
29
  end
27
30
  rescue ActiveStorage::IntegrityError
28
31
  head :unprocessable_entity
@@ -8,7 +8,7 @@ class ActiveStorage::RepresentationsController < ActiveStorage::BaseController
8
8
  include ActiveStorage::SetBlob
9
9
 
10
10
  def show
11
- expires_in ActiveStorage::Blob.service.url_expires_in
11
+ expires_in ActiveStorage.service_urls_expire_in
12
12
  redirect_to @blob.representation(params[:variation_key]).processed.service_url(disposition: params[:disposition])
13
13
  end
14
14
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Sets the <tt>ActiveStorage::Current.host</tt> attribute, which the disk service uses to generate URLs.
4
+ # Include this concern in custom controllers that call ActiveStorage::Blob#service_url,
5
+ # ActiveStorage::Variant#service_url, or ActiveStorage::Preview#service_url so the disk service can
6
+ # generate URLs using the same host, protocol, and base path as the current request.
7
+ module ActiveStorage::SetCurrent
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ before_action do
12
+ ActiveStorage::Current.host = request.base_url
13
+ end
14
+ end
15
+ end
@@ -17,7 +17,12 @@ export class BlobRecord {
17
17
  this.xhr.setRequestHeader("Content-Type", "application/json")
18
18
  this.xhr.setRequestHeader("Accept", "application/json")
19
19
  this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
20
- this.xhr.setRequestHeader("X-CSRF-Token", getMetaValue("csrf-token"))
20
+
21
+ const csrfToken = getMetaValue("csrf-token")
22
+ if (csrfToken != undefined) {
23
+ this.xhr.setRequestHeader("X-CSRF-Token", csrfToken)
24
+ }
25
+
21
26
  this.xhr.addEventListener("load", event => this.requestDidLoad(event))
22
27
  this.xhr.addEventListener("error", event => this.requestDidError(event))
23
28
  }