omg-activestorage 8.0.0.alpha3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +21 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +208 -0
  5. data/app/assets/javascripts/activestorage.esm.js +848 -0
  6. data/app/assets/javascripts/activestorage.js +830 -0
  7. data/app/controllers/active_storage/base_controller.rb +10 -0
  8. data/app/controllers/active_storage/blobs/proxy_controller.rb +26 -0
  9. data/app/controllers/active_storage/blobs/redirect_controller.rb +16 -0
  10. data/app/controllers/active_storage/direct_uploads_controller.rb +23 -0
  11. data/app/controllers/active_storage/disk_controller.rb +57 -0
  12. data/app/controllers/active_storage/representations/base_controller.rb +18 -0
  13. data/app/controllers/active_storage/representations/proxy_controller.rb +18 -0
  14. data/app/controllers/active_storage/representations/redirect_controller.rb +14 -0
  15. data/app/controllers/concerns/active_storage/disable_session.rb +12 -0
  16. data/app/controllers/concerns/active_storage/file_server.rb +21 -0
  17. data/app/controllers/concerns/active_storage/set_blob.rb +20 -0
  18. data/app/controllers/concerns/active_storage/set_current.rb +15 -0
  19. data/app/controllers/concerns/active_storage/streaming.rb +75 -0
  20. data/app/javascript/activestorage/blob_record.js +76 -0
  21. data/app/javascript/activestorage/blob_upload.js +35 -0
  22. data/app/javascript/activestorage/direct_upload.js +49 -0
  23. data/app/javascript/activestorage/direct_upload_controller.js +67 -0
  24. data/app/javascript/activestorage/direct_uploads_controller.js +50 -0
  25. data/app/javascript/activestorage/file_checksum.js +53 -0
  26. data/app/javascript/activestorage/helpers.js +51 -0
  27. data/app/javascript/activestorage/index.js +14 -0
  28. data/app/javascript/activestorage/ujs.js +86 -0
  29. data/app/jobs/active_storage/analyze_job.rb +13 -0
  30. data/app/jobs/active_storage/base_job.rb +4 -0
  31. data/app/jobs/active_storage/mirror_job.rb +15 -0
  32. data/app/jobs/active_storage/preview_image_job.rb +16 -0
  33. data/app/jobs/active_storage/purge_job.rb +13 -0
  34. data/app/jobs/active_storage/transform_job.rb +12 -0
  35. data/app/models/active_storage/attachment.rb +176 -0
  36. data/app/models/active_storage/blob/analyzable.rb +62 -0
  37. data/app/models/active_storage/blob/identifiable.rb +33 -0
  38. data/app/models/active_storage/blob/representable.rb +137 -0
  39. data/app/models/active_storage/blob/servable.rb +22 -0
  40. data/app/models/active_storage/blob.rb +396 -0
  41. data/app/models/active_storage/current.rb +5 -0
  42. data/app/models/active_storage/filename.rb +75 -0
  43. data/app/models/active_storage/named_variant.rb +21 -0
  44. data/app/models/active_storage/preview.rb +131 -0
  45. data/app/models/active_storage/record.rb +7 -0
  46. data/app/models/active_storage/variant.rb +118 -0
  47. data/app/models/active_storage/variant_record.rb +8 -0
  48. data/app/models/active_storage/variant_with_record.rb +72 -0
  49. data/app/models/active_storage/variation.rb +87 -0
  50. data/config/routes.rb +84 -0
  51. data/db/migrate/20170806125915_create_active_storage_tables.rb +56 -0
  52. data/db/update_migrate/20190112182829_add_service_name_to_active_storage_blobs.rb +21 -0
  53. data/db/update_migrate/20191206030411_create_active_storage_variant_records.rb +26 -0
  54. data/db/update_migrate/20211119233751_remove_not_null_on_active_storage_blobs_checksum.rb +7 -0
  55. data/lib/active_storage/analyzer/audio_analyzer.rb +77 -0
  56. data/lib/active_storage/analyzer/image_analyzer/image_magick.rb +41 -0
  57. data/lib/active_storage/analyzer/image_analyzer/vips.rb +47 -0
  58. data/lib/active_storage/analyzer/image_analyzer.rb +29 -0
  59. data/lib/active_storage/analyzer/null_analyzer.rb +17 -0
  60. data/lib/active_storage/analyzer/video_analyzer.rb +157 -0
  61. data/lib/active_storage/analyzer.rb +50 -0
  62. data/lib/active_storage/attached/changes/create_many.rb +56 -0
  63. data/lib/active_storage/attached/changes/create_one.rb +129 -0
  64. data/lib/active_storage/attached/changes/create_one_of_many.rb +14 -0
  65. data/lib/active_storage/attached/changes/delete_many.rb +27 -0
  66. data/lib/active_storage/attached/changes/delete_one.rb +19 -0
  67. data/lib/active_storage/attached/changes/detach_many.rb +18 -0
  68. data/lib/active_storage/attached/changes/detach_one.rb +24 -0
  69. data/lib/active_storage/attached/changes/purge_many.rb +27 -0
  70. data/lib/active_storage/attached/changes/purge_one.rb +27 -0
  71. data/lib/active_storage/attached/changes.rb +22 -0
  72. data/lib/active_storage/attached/many.rb +79 -0
  73. data/lib/active_storage/attached/model.rb +280 -0
  74. data/lib/active_storage/attached/one.rb +86 -0
  75. data/lib/active_storage/attached.rb +27 -0
  76. data/lib/active_storage/deprecator.rb +7 -0
  77. data/lib/active_storage/downloader.rb +43 -0
  78. data/lib/active_storage/engine.rb +205 -0
  79. data/lib/active_storage/errors.rb +29 -0
  80. data/lib/active_storage/fixture_set.rb +79 -0
  81. data/lib/active_storage/gem_version.rb +17 -0
  82. data/lib/active_storage/log_subscriber.rb +76 -0
  83. data/lib/active_storage/previewer/mupdf_previewer.rb +40 -0
  84. data/lib/active_storage/previewer/poppler_pdf_previewer.rb +39 -0
  85. data/lib/active_storage/previewer/video_previewer.rb +36 -0
  86. data/lib/active_storage/previewer.rb +101 -0
  87. data/lib/active_storage/reflection.rb +74 -0
  88. data/lib/active_storage/service/azure_storage_service.rb +201 -0
  89. data/lib/active_storage/service/configurator.rb +36 -0
  90. data/lib/active_storage/service/disk_service.rb +178 -0
  91. data/lib/active_storage/service/gcs_service.rb +232 -0
  92. data/lib/active_storage/service/mirror_service.rb +93 -0
  93. data/lib/active_storage/service/registry.rb +32 -0
  94. data/lib/active_storage/service/s3_service.rb +171 -0
  95. data/lib/active_storage/service.rb +180 -0
  96. data/lib/active_storage/transformers/image_processing_transformer.rb +110 -0
  97. data/lib/active_storage/transformers/transformer.rb +41 -0
  98. data/lib/active_storage/version.rb +10 -0
  99. data/lib/active_storage.rb +374 -0
  100. data/lib/tasks/activestorage.rake +26 -0
  101. metadata +217 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '048a04352709d70078e220eca5167d5570cfb31ceca5042583f584708dde5eda'
4
+ data.tar.gz: a4c65ebb18c487449c54578882852465b0f3bc6b0411bd7368f10572cc155d31
5
+ SHA512:
6
+ metadata.gz: c8ff83c283d8157af3d1b8c6793acb7e25de849f3a1c18a08d693af03fd04fc5d621df661d5a866709da1b0f198729dcb1f2c4b38823e893e9188b97b1476de1
7
+ data.tar.gz: 125ea5c93335978791e6de6f2e4dbb6713bac48bdb5567d7ac8b111ef179fb685a41b8031e969e6f29a7a4975bb24351dc1df5c1be34400560bbefffddc684c4
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ * Deprecate `ActiveStorage::Service::AzureStorageService`.
2
+
3
+ *zzak*
4
+
5
+ * Improve `ActiveStorage::Filename#sanitized` method to handle special characters more effectively.
6
+ Replace the characters `"*?<>` with `-` if they exist in the Filename to match the Filename convention of Win OS.
7
+
8
+ *Luong Viet Dung(Martin)*
9
+
10
+ * Improve InvariableError, UnpreviewableError and UnrepresentableError message.
11
+
12
+ Include Blob ID and content_type in the messages.
13
+
14
+ *Petrik de Heus*
15
+
16
+ * Mark proxied files as `immutable` in their Cache-Control header
17
+
18
+ *Nate Matykiewicz*
19
+
20
+
21
+ Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activestorage/CHANGELOG.md) for previous changes.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) David Heinemeier Hansson, 37signals LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # Active Storage
2
+
3
+ Active Storage makes it simple to upload and reference files in cloud services like [Amazon S3](https://aws.amazon.com/s3/), [Google Cloud Storage](https://cloud.google.com/storage/docs/), or [Microsoft Azure Storage](https://azure.microsoft.com/en-us/services/storage/), and attach those files to Active Records. Supports having one main service and mirrors in other services for redundancy. It also provides a disk service for testing or local deployments, but the focus is on cloud storage.
4
+
5
+ Files can be uploaded from the server to the cloud or directly from the client to the cloud.
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) 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://guides.rubyonrails.org/active_storage_overview.html) guide.
10
+
11
+ ## Compared to other storage solutions
12
+
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/main/activestorage/app/models/active_storage/blob.rb) and [Attachment](https://github.com/rails/rails/blob/main/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`.
14
+
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).
16
+
17
+ ## Installation
18
+
19
+ Run `bin/rails active_storage:install` to copy over active_storage migrations.
20
+
21
+ NOTE: If the task cannot be found, verify that `require "active_storage/engine"` is present in `config/application.rb`.
22
+
23
+ ## Examples
24
+
25
+ One attachment:
26
+
27
+ ```ruby
28
+ class User < ApplicationRecord
29
+ # Associates an attachment and a blob. When the user is destroyed they are
30
+ # purged by default (models destroyed, and resource files deleted).
31
+ has_one_attached :avatar
32
+ end
33
+
34
+ # Attach an avatar to the user.
35
+ user.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpeg")
36
+
37
+ # Does the user have an avatar?
38
+ user.avatar.attached? # => true
39
+
40
+ # Synchronously destroy the avatar and actual resource files.
41
+ user.avatar.purge
42
+
43
+ # Destroy the associated models and actual resource files async, via Active Job.
44
+ user.avatar.purge_later
45
+
46
+ # Does the user have an avatar?
47
+ user.avatar.attached? # => false
48
+
49
+ # Generate a permanent URL for the blob that points to the application.
50
+ # Upon access, a redirect to the actual service endpoint is returned.
51
+ # This indirection decouples the public URL from the actual one, and
52
+ # allows for example mirroring attachments in different services for
53
+ # high-availability. The redirection has an HTTP expiration of 5 min.
54
+ url_for(user.avatar)
55
+
56
+ class AvatarsController < ApplicationController
57
+ def update
58
+ # params[:avatar] contains an ActionDispatch::Http::UploadedFile object
59
+ Current.user.avatar.attach(params.require(:avatar))
60
+ redirect_to Current.user
61
+ end
62
+ end
63
+ ```
64
+
65
+ Many attachments:
66
+
67
+ ```ruby
68
+ class Message < ApplicationRecord
69
+ has_many_attached :images
70
+ end
71
+ ```
72
+
73
+ ```erb
74
+ <%= form_with model: @message, local: true do |form| %>
75
+ <%= form.text_field :title, placeholder: "Title" %><br>
76
+ <%= form.textarea :content %><br><br>
77
+
78
+ <%= form.file_field :images, multiple: true %><br>
79
+ <%= form.submit %>
80
+ <% end %>
81
+ ```
82
+
83
+ ```ruby
84
+ class MessagesController < ApplicationController
85
+ def index
86
+ # Use the built-in with_attached_images scope to avoid N+1
87
+ @messages = Message.all.with_attached_images
88
+ end
89
+
90
+ def create
91
+ message = Message.create! params.expect(message: [ :title, :content, images: [] ])
92
+ redirect_to message
93
+ end
94
+
95
+ def show
96
+ @message = Message.find(params[:id])
97
+ end
98
+ end
99
+ ```
100
+
101
+ Variation of image attachment:
102
+
103
+ ```erb
104
+ <%# Hitting the variant URL will lazy transform the original blob and then redirect to its new service location %>
105
+ <%= image_tag user.avatar.variant(resize_to_limit: [100, 100]) %>
106
+ ```
107
+
108
+ ## File serving strategies
109
+
110
+ Active Storage supports two ways to serve files: redirecting and proxying.
111
+
112
+ ### Redirecting
113
+
114
+ Active Storage generates stable application URLs for files which, when accessed, redirect to signed, short-lived service URLs. This relieves application servers of the burden of serving file data. It is the default file serving strategy.
115
+
116
+ When the application is configured to proxy files by default, use the `rails_storage_redirect_path` and `_url` route helpers to redirect instead:
117
+
118
+ ```erb
119
+ <%= image_tag rails_storage_redirect_path(@user.avatar) %>
120
+ ```
121
+
122
+ ### Proxying
123
+
124
+ Optionally, files can be proxied instead. This means that your application servers will download file data from the storage service in response to requests. This can be useful for serving files from a CDN.
125
+
126
+ You can configure Active Storage to use proxying by default:
127
+
128
+ ```ruby
129
+ # config/initializers/active_storage.rb
130
+ Rails.application.config.active_storage.resolve_model_to_route = :rails_storage_proxy
131
+ ```
132
+
133
+ Or if you want to explicitly proxy specific attachments there are URL helpers you can use in the form of `rails_storage_proxy_path` and `rails_storage_proxy_url`.
134
+
135
+ ```erb
136
+ <%= image_tag rails_storage_proxy_path(@user.avatar) %>
137
+ ```
138
+
139
+ ## Direct uploads
140
+
141
+ Active Storage, with its included JavaScript library, supports uploading directly from the client to the cloud.
142
+
143
+ ### Direct upload installation
144
+
145
+ 1. Include the Active Storage JavaScript in your application's JavaScript bundle or reference it directly.
146
+
147
+ Requiring directly without bundling through the asset pipeline in the application HTML with autostart:
148
+ ```erb
149
+ <%= javascript_include_tag "activestorage" %>
150
+ ```
151
+ Requiring via importmap-rails without bundling through the asset pipeline in the application HTML without autostart as ESM:
152
+ ```ruby
153
+ # config/importmap.rb
154
+ pin "@rails/activestorage", to: "activestorage.esm.js"
155
+ ```
156
+ ```html
157
+ <script type="module-shim">
158
+ import * as ActiveStorage from "@rails/activestorage"
159
+ ActiveStorage.start()
160
+ </script>
161
+ ```
162
+ Using the asset pipeline:
163
+ ```js
164
+ //= require activestorage
165
+ ```
166
+ Using the npm package:
167
+ ```js
168
+ import * as ActiveStorage from "@rails/activestorage"
169
+ ActiveStorage.start()
170
+ ```
171
+ 2. Annotate file inputs with the direct upload URL.
172
+
173
+ ```erb
174
+ <%= form.file_field :attachments, multiple: true, direct_upload: true %>
175
+ ```
176
+ 3. That's it! Uploads begin upon form submission.
177
+
178
+ ### Direct upload JavaScript events
179
+
180
+ | Event name | Event target | Event data (`event.detail`) | Description |
181
+ | --- | --- | --- | --- |
182
+ | `direct-uploads:start` | `<form>` | None | A form containing files for direct upload fields was submitted. |
183
+ | `direct-upload:initialize` | `<input>` | `{id, file}` | Dispatched for every file after form submission. |
184
+ | `direct-upload:start` | `<input>` | `{id, file}` | A direct upload is starting. |
185
+ | `direct-upload:before-blob-request` | `<input>` | `{id, file, xhr}` | Before making a request to your application for direct upload metadata. |
186
+ | `direct-upload:before-storage-request` | `<input>` | `{id, file, xhr}` | Before making a request to store a file. |
187
+ | `direct-upload:progress` | `<input>` | `{id, file, progress}` | As requests to store files progress. |
188
+ | `direct-upload:error` | `<input>` | `{id, file, error}` | An error occurred. An `alert` will display unless this event is canceled. |
189
+ | `direct-upload:end` | `<input>` | `{id, file}` | A direct upload has ended. |
190
+ | `direct-uploads:end` | `<form>` | None | All direct uploads have ended. |
191
+
192
+ ## License
193
+
194
+ Active Storage is released under the [MIT License](https://opensource.org/licenses/MIT).
195
+
196
+ ## Support
197
+
198
+ API documentation is at:
199
+
200
+ * https://api.rubyonrails.org
201
+
202
+ Bug reports for the Ruby on \Rails project can be filed here:
203
+
204
+ * https://github.com/rails/rails/issues
205
+
206
+ Feature requests should be discussed on the rails-core mailing list here:
207
+
208
+ * https://discuss.rubyonrails.org/c/rubyonrails-core