activestorage 5.2.3 → 6.0.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 +153 -59
  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 +84 -31
  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 +3 -3
  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 +24 -12
  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 +42 -13
  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: 077c1da19deeca0ecb5c0a29368bc1a2f54efacf2b988952711aa954692dd0a6
4
- data.tar.gz: '090e05af4c46201d10d8b32a3f3c3ae4da6e7195a8b84d670882f15bfc244390'
3
+ metadata.gz: 552504b488cd3a71744bf26402444008d417219053f2aaf0d56cedda76c98fd2
4
+ data.tar.gz: 6d1e4241db656db0397763c982789e0336b8cbcaa8c06cda48f9707118e967e6
5
5
  SHA512:
6
- metadata.gz: a56d7375b12d9171df2a3787ddb2a6c52e442bc7284b2e9baf1a6177ff59100e1e4e6c9feb78d322f8ef1af822b205f9f9d8b84e3c1b9bdedc1ecffda49c2c88
7
- data.tar.gz: 2d2d164bc9c34f032b443a2db7e9645d36cb4cab4a68dfc03b486071dcf568a40a6b373cd47e170b092259ab31a023a35a280f93c9ec9bbe77a398a08c6c987f
6
+ metadata.gz: 96773f10ef5074d0cf9f112e8b881034c94c04d9d1b370179aebb926be2ce9fc344faf7db6a9104475f852af11afae2576650f4398866fd622dadbdb554e46d1
7
+ data.tar.gz: 5a444b03f9a8ff6e6ee16c9f847049894fb84a8f2dbede5f6829855fc53d63f3b5135e75f46c3d285efbbe0ee7bb4d09333ac331ae5cc28af8f015cbb15f5732
@@ -1,117 +1,211 @@
1
- ## Rails 5.2.3 (March 27, 2019) ##
1
+ ## Rails 6.0.1 (November 5, 2019) ##
2
+
3
+ * `ActiveStorage::AnalyzeJob`s are discarded on `ActiveRecord::RecordNotFound` errors.
4
+
5
+ *George Claghorn*
6
+
7
+ * Blobs are recorded in the database before being uploaded to the service.
8
+ This fixes that generated blob keys could silently collide, leading to
9
+ data loss.
10
+
11
+ *Julik Tarkhanov*
12
+
13
+
14
+ ## Rails 6.0.0 (August 16, 2019) ##
2
15
 
3
16
  * No changes.
4
17
 
5
18
 
6
- ## Rails 5.2.2.1 (March 11, 2019) ##
19
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
7
20
 
8
21
  * No changes.
9
22
 
10
23
 
11
- ## Rails 5.2.2 (December 04, 2018) ##
24
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
12
25
 
13
- * Support multiple submit buttons in Active Storage forms.
26
+ * Don't raise when analyzing an image whose type is unsupported by ImageMagick.
14
27
 
15
- *Chrıs Seelus*
28
+ Fixes #36065.
16
29
 
17
- * Fix `ArgumentError` when uploading to amazon s3
30
+ *Guilherme Mansur*
18
31
 
19
- *Hiroki Sanpei*
32
+ * Permit generating variants of BMP images.
20
33
 
21
- * Add a foreign-key constraint to the `active_storage_attachments` table for blobs.
34
+ *Younes Serraj*
22
35
 
23
- *George Claghorn*
24
36
 
25
- * Discard `ActiveStorage::PurgeJobs` for missing blobs.
37
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
26
38
 
27
- *George Claghorn*
39
+ * No changes.
28
40
 
29
- * Fix uploading Tempfiles to Azure Storage.
30
41
 
31
- *George Claghorn*
42
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
32
43
 
44
+ * No changes.
33
45
 
34
- ## Rails 5.2.1.1 (November 27, 2018) ##
35
46
 
36
- * Prevent content type and disposition bypass in storage service URLs.
47
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
37
48
 
38
- Fix CVE-2018-16477.
49
+ * [Rename npm package](https://github.com/rails/rails/pull/34905) from
50
+ [`activestorage`](https://www.npmjs.com/package/activestorage) to
51
+ [`@rails/activestorage`](https://www.npmjs.com/package/@rails/activestorage).
39
52
 
40
- *Rosa Gutierrez*
53
+ *Javan Makhmali*
41
54
 
55
+ * Replace `config.active_storage.queue` with two options that indicate which
56
+ queues analysis and purge jobs should use, respectively:
42
57
 
43
- ## Rails 5.2.1 (August 07, 2018) ##
58
+ * `config.active_storage.queues.analysis`
59
+ * `config.active_storage.queues.purge`
44
60
 
45
- * Fix direct upload with zero-byte files.
61
+ `config.active_storage.queue` is preferred over the new options when it's
62
+ set, but it is deprecated and will be removed in Rails 6.1.
46
63
 
47
64
  *George Claghorn*
48
65
 
49
- * Exclude JSON root from `active_storage/direct_uploads#create` response.
66
+ * Permit generating variants of TIFF images.
50
67
 
51
- *Javan Makhmali*
68
+ *Luciano Sousa*
69
+
70
+ * Use base36 (all lowercase) for all new Blob keys to prevent
71
+ collisions and undefined behavior with case-insensitive filesystems and
72
+ database indices.
73
+
74
+ *Julik Tarkhanov*
75
+
76
+ * It doesn’t include an `X-CSRF-Token` header if a meta tag is not found on
77
+ the page. It previously included one with a value of `undefined`.
78
+
79
+ *Cameron Bothner*
52
80
 
81
+ * Fix `ArgumentError` when uploading to amazon s3
82
+
83
+ *Hiroki Sanpei*
84
+
85
+ * Add progressive JPG to default list of variable content types
86
+
87
+ *Maurice Kühlborn*
88
+
89
+ * Add `ActiveStorage.routes_prefix` for configuring generated routes.
90
+
91
+ *Chris Bisnett*
92
+
93
+ * `ActiveStorage::Service::AzureStorageService` only handles specifically
94
+ relevant types of `Azure::Core::Http::HTTPError`. It previously obscured
95
+ other types of `HTTPError`, which is the azure-storage gem’s catch-all
96
+ exception class.
97
+
98
+ *Cameron Bothner*
99
+
100
+ * `ActiveStorage::DiskController#show` generates a 404 Not Found response when
101
+ the requested file is missing from the disk service. It previously raised
102
+ `Errno::ENOENT`.
53
103
 
54
- ## Rails 5.2.0 (April 09, 2018) ##
104
+ *Cameron Bothner*
55
105
 
56
- * Allow full use of the AWS S3 SDK options for authentication. If an
57
- explicit AWS key pair and/or region is not provided in `storage.yml`,
58
- attempt to use environment variables, shared credentials, or IAM
59
- (instance or task) role credentials. Order of precedence is determined
60
- by the [AWS SDK](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html).
106
+ * `ActiveStorage::Blob#download` and `ActiveStorage::Blob#open` raise
107
+ `ActiveStorage::FileNotFoundError` when the corresponding file is missing
108
+ from the storage service. Services translate service-specific missing object
109
+ exceptions (e.g. `Google::Cloud::NotFoundError` for the GCS service and
110
+ `Errno::ENOENT` for the disk service) into
111
+ `ActiveStorage::FileNotFoundError`.
61
112
 
62
- *Brian Knight*
113
+ *Cameron Bothner*
63
114
 
64
- * Remove path config option from Azure service.
115
+ * Added the `ActiveStorage::SetCurrent` concern for custom Active Storage
116
+ controllers that can't inherit from `ActiveStorage::BaseController`.
65
117
 
66
- The Active Storage service for Azure Storage has an option called `path`
67
- that is ambiguous in meaning. It needs to be set to the primary blob
68
- storage endpoint but that can be determined from the blobs client anyway.
118
+ *George Claghorn*
119
+
120
+ * Active Storage error classes like `ActiveStorage::IntegrityError` and
121
+ `ActiveStorage::UnrepresentableError` now inherit from `ActiveStorage::Error`
122
+ instead of `StandardError`. This permits rescuing `ActiveStorage::Error` to
123
+ handle all Active Storage errors.
69
124
 
70
- To simplify the configuration, we've removed the `path` option and
71
- now get the endpoint from the blobs client instead.
125
+ *Andrei Makarov*, *George Claghorn*
72
126
 
73
- Closes #32225.
127
+ * Uploaded files assigned to a record are persisted to storage when the record
128
+ is saved instead of immediately.
74
129
 
75
- *Andrew White*
130
+ In Rails 5.2, the following causes an uploaded file in `params[:avatar]` to
131
+ be stored:
76
132
 
77
- * Generate root-relative paths in disk service URL methods.
133
+ ```ruby
134
+ @user.avatar = params[:avatar]
135
+ ```
78
136
 
79
- Obviate the disk service's `:host` configuration option.
137
+ In Rails 6, the uploaded file is stored when `@user` is successfully saved.
80
138
 
81
139
  *George Claghorn*
82
140
 
83
- * Add source code to published npm package.
141
+ * Add the ability to reflect on defined attachments using the existing
142
+ ActiveRecord reflection mechanism.
143
+
144
+ *Kevin Deisz*
145
+
146
+ * Variant arguments of `false` or `nil` will no longer be passed to the
147
+ processor. For example, the following will not have the monochrome
148
+ variation applied:
149
+
150
+ ```ruby
151
+ avatar.variant(monochrome: false)
152
+ ```
153
+
154
+ *Jacob Smith*
155
+
156
+ * Generated attachment getter and setter methods are created
157
+ within the model's `GeneratedAssociationMethods` module to
158
+ allow overriding and composition using `super`.
159
+
160
+ *Josh Susser*, *Jamon Douglas*
161
+
162
+ * Add `ActiveStorage::Blob#open`, which downloads a blob to a tempfile on disk
163
+ and yields the tempfile. Deprecate `ActiveStorage::Downloading`.
164
+
165
+ *David Robertson*, *George Claghorn*
84
166
 
85
- This allows activestorage users to depend on the javascript source code
86
- rather than the compiled code, which can produce smaller javascript bundles.
167
+ * Pass in `identify: false` as an argument when providing a `content_type` for
168
+ `ActiveStorage::Attached::{One,Many}#attach` to bypass automatic content
169
+ type inference. For example:
87
170
 
88
- *Richard Macklin*
171
+ ```ruby
172
+ @message.image.attach(
173
+ io: File.open('/path/to/file'),
174
+ filename: 'file.pdf',
175
+ content_type: 'application/pdf',
176
+ identify: false
177
+ )
178
+ ```
89
179
 
90
- * Preserve display aspect ratio when extracting width and height from videos
91
- with rectangular samples in `ActiveStorage::Analyzer::VideoAnalyzer`.
180
+ *Ryan Davidson*
92
181
 
93
- When a video contains a display aspect ratio, emit it in metadata as
94
- `:display_aspect_ratio` rather than the ambiguous `:aspect_ratio`. Compute
95
- its height by scaling its encoded frame width according to the DAR.
182
+ * The Google Cloud Storage service properly supports streaming downloads.
183
+ It now requires version 1.11 or newer of the google-cloud-storage gem.
96
184
 
97
185
  *George Claghorn*
98
186
 
99
- * Use `after_destroy_commit` instead of `before_destroy` for purging
100
- attachments when a record is destroyed.
187
+ * Use the [ImageProcessing](https://github.com/janko-m/image_processing) gem
188
+ for Active Storage variants, and deprecate the MiniMagick backend.
101
189
 
102
- *Hiroki Zenigami*
190
+ This means that variants are now automatically oriented if the original
191
+ image was rotated. Also, in addition to the existing ImageMagick
192
+ operations, variants can now use `:resize_to_fit`, `:resize_to_fill`, and
193
+ other ImageProcessing macros. These are now recommended over raw `:resize`,
194
+ as they also sharpen the thumbnail after resizing.
103
195
 
104
- * Force `:attachment` disposition for specific, configurable content types.
105
- This mitigates possible security issues such as XSS or phishing when
106
- serving them inline. A list of such content types is included by default,
107
- and can be configured via `content_types_to_serve_as_binary`.
196
+ The ImageProcessing gem also comes with a backend implemented on
197
+ [libvips](http://jcupitt.github.io/libvips/), an alternative to
198
+ ImageMagick which has significantly better performance than
199
+ ImageMagick in most cases, both in terms of speed and memory usage. In
200
+ Active Storage it's now possible to switch to the libvips backend by
201
+ changing `Rails.application.config.active_storage.variant_processor` to
202
+ `:vips`.
108
203
 
109
- *Rosa Gutierrez*
204
+ *Janko Marohnić*
110
205
 
111
- * Fix the gem adding the migrations files to the package.
206
+ * Rails 6 requires Ruby 2.5.0 or newer.
112
207
 
113
- *Yuji Yaginuma*
208
+ *Jeremy Daer*, *Kasper Timm Hansen*
114
209
 
115
- * Added to Rails.
116
210
 
117
- *DHH*
211
+ 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
  }