Commit Graph

186 Commits

Author SHA1 Message Date
Nate Matykiewicz
78ad54569b
Make http_cache_forever use immutable: true 2024-07-06 01:59:39 -05:00
Rafael Mendonça França
bf59d363fb
Clean CHANGELOG for 8.0 2024-05-13 16:55:52 +00:00
Rafael Mendonça França
37fd0e7fe4
Development of Rails 8.0 starts now
🎉
2024-05-13 16:45:20 +00:00
Rafael Mendonça França
0cf8444d61
Remove deprecated config.active_storage.silence_invalid_content_types_warning 2024-05-01 18:44:30 +00:00
Rafael Mendonça França
b06252e2a7
Remove deprecated config.active_storage.replace_on_assign_to_many 2024-05-01 18:44:29 +00:00
Elvin Efendiev
64178f998e Support custom blob key in ActiveStorage::Blob#compose similar to other Blob APIs 2024-03-11 17:27:19 -04:00
Lewis Buckley
f3e3f82e7d
Add WebP as a new framework default image type
Follows https://github.com/rails/rails/pull/38918 and
https://github.com/rails/rails/pull/38988

At the time, webp browser support was limited. Now 96% of browsers
support webp: https://caniuse.com/?search=webp
2024-02-09 23:44:51 +00:00
Jonathan del Strother
54d3934d43
Fix JSON-encoding ActiveStorage::Filename
ActiveStorage::Filename was missing quotes when encoded,
generating invalid json like this -

```
JSON.generate(foo: ActiveStorage::Filename.new("bar.pdf") # => '{"foo":bar.pdf}'
```

Delete to_json and rely on the implementation from ActiveSupport::ToJsonWithActiveSupportEncoder
2024-02-06 12:37:58 +00:00
Aaron Patterson
7e9b5889cc
update changelog 2024-01-16 09:36:44 -08:00
chaadow
4ca61ffacb Take AR affixes into account for AStorage models
All of ActiveStorage database modeltable nameshave been hard coded.
Therefore, ActiveRecord::Base.(prefix|suffix) were not taken into
consideration. To fix this we remove the hard coded lines. But then we
need to also override an internal method for specifying the prefix
because of a mystical ActiveRecord/ActiveStorage sync issue
(Suffix does not appear to have the issue)

Some tests were refactored to remove hard coded table name references,
making ActiveStorage test suite compatible with ActiveRecord config.
2023-12-07 00:01:16 +01:00
chaadow
f5acef7e48 Fix AS:Representations::ProxyController returning the wrong preview
When a blob is a representable of kind `previewable`, the preview
image that's being proxied is always the original preview image,
discarding completely the `variation_key` param passed in the request.

This commit fixes this by editing `Preview` and `VariantWithRecord` to
have full synchronized API with `Variant`. this will then allow the
ProxyController to not call `representable#image` but `representable`
instead.

As all 3 classes are now 100% interchangeable, we can deprecate the use
of `Representable#image`. Users of this class won't need to call this
method as it's become obsolete. and in case of `Preview#image`
erroneous.
2023-11-21 21:00:35 +01:00
chaadow
cb3fdaf8e4 Fix representation proxy for untracked variants
`ActiveStorage::Variant`, the class used to handle untracked variants,
is lacking some methods to make it compliant with
`ActiveStorage::Representations::ProxyController#send_blob_stream`.

This commit fixes the proxying of untracked variant by adding the
missing methods.
2023-11-20 19:57:01 +01:00
Jonathan Hefner
e514c586f1 Add CHANGELOG entry for #50082 [ci-skip] 2023-11-17 16:43:39 -06:00
chaadow
eae19656fe Prevent AS::Preview#processed to generate an empty variant
if an empty hash is passed to a preview call (`blob.preview({})`)
We go through the original preview instead of regenerating a variation
based on the original preview image which would result in a performance
penalty
2023-11-15 21:01:16 +01:00
Jonathan Hefner
a5e1fc97d2 Process preview variant when processing preview
Prior to this commit, `ActiveStorage::Preview#processed` would only
process the preview image, not the specified variant of the preview
image.  For example, `thumb = attached_pdf.preview(:thumb).processed`
would only generate the full-sized preview image, not the `:thumb`
variant of it, until e.g. `thumb.url` was called.

This commit updates `ActiveStorage::Preview#processed` to generate both
the full-sized preview image and the requested variant.

Co-authored-by: chaadow <chedli@hoggo.com>
2023-11-13 11:01:40 -06:00
Jonathan Hefner
aa47bde556 Fix strict loading for Active Storage previews
`ActiveStorage::Preview#url` delegates to the preview image's variant,
which in turn delegates to the variant's blob.  Thus when the variant
has already been processed and strict loading is enabled, the
association chain of `preview_image_attachment` => `blob` =>
`variant_records` => `image_attachment` => `blob` must be fully
pre-loaded; otherwise, `ActiveStorage::Preview#url` will raise an
`ActiveRecord::StrictLoadingViolationError`.
2023-11-13 10:58:50 -06:00
Nico Wenterodt
435a347a10 Fix #50005 transform_job not accepting previewables
The transform_job crahes if you want to preprocess a previewable files.
This commit fixes that by using the blob's `representation` method to
process variants or previews.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-11 11:21:00 -06:00
Yogesh Khater
8bf1353cae Allow accepting service as a proc
`service` kwarg in `has_one_attached` and `has_many_attached` methods accepts
only symbols as values. It allows to define a `service` at a class-level context. But in
one of our requirements, we wanted to upload files based on user's region due to
some regulations.

So in order to allow defining a `service` at instance-level context,
this PR makes the changes to accept `service` as a Proc as well.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-01 21:20:55 -05:00
Rafael Mendonça França
fb6c6007d0
Development of Rails 7.2 starts now
🎉
2023-09-27 03:59:11 +00:00
Rafael Mendonça França
e5386cb402
Preparing for 7.1.0.rc1 release 2023-09-27 03:08:31 +00:00
aki
1f9fbbe213
Add expires_at option to ActiveStorage::Blob#signed_id 2023-09-26 21:08:20 +00:00
Dorian Marié
22bacd710d Allow attaching File or Pathname to has_one_attached
### Why was this change necessary?

When creating models in tests, it's easier to pass a File or a Pathname
(from `file_fixture` for instance) to `Model.create` for instance

### How does it address the problem?

When attaching an attachable, we check if it's a File or a Pathname and
handle it appropriately.
2023-09-25 13:43:26 +02:00
Rafael Mendonça França
699dfdb426
Preparing for 7.1.0.beta1 release 2023-09-13 00:36:01 +00:00
Akhil G Krishnan
61a9c1a92a Ruby code block indentation issue fix
[skip ci] indentation fix

[skip ci] review changes added

[skip ci] indentation fix
2023-09-07 01:14:48 +05:30
Bruno Prieto
8a88ce1943 Disable session in ActiveStorage blobs and representations proxy controller
This allows CDNs such as CloudFlare to cache files delivered by proxy by default

Fix #44136
2023-08-02 06:44:51 +02:00
Keaton Roux
dc4eb0f3b5 Add tags to audio analyzer metadata 2023-07-27 10:30:49 +02:00
Shouichi Kamiya
b1c544b1d1 Add an option to preprocessed AS variants
ActiveStorage variants are processed on the fly when they are needed but
sometimes we're sure that they are accessed and want to processed them
upfront.

`preprocessed` option is added when declaring variants.

```
class User < ApplicationRecord
  has_one_attached :avatar do |attachable|
    attachable.variant :thumb, resize_to_limit: [100, 100], preprocessed: true
  end
end
```
2023-07-03 19:36:14 +09:00
Russell Porter
19e0dd9773 Include variants when eager loading attachment
Fixes an explosion of active storage queries when accessing variants for multiple records.

The implementation is now consistent with that of `has_many_attached`.
2023-06-29 17:04:07 +00:00
Nate Matykiewicz
dd894b2fc2
Allow an ActiveStorage attachment to be removed via a form post
Attachments can already be removed by updating the attachment to be nil such as:
```ruby
User.find(params[:id]).update!(avatar: nil)
```

However, a form cannot post a nil param, it can only post an empty string. But, posting an
empty string would result in an `ActiveSupport::MessageVerifier::InvalidSignature: mismatched digest`
error being raised, because it's being treated as a signed blob id.

Now, nil and an empty string are treated as a delete, which allows attachments to be removed via:
```ruby
User.find(params[:id]).update!(params.require(:user).permit(:avatar))

```
2023-05-29 22:58:25 -05:00
Rafael Mendonça França
1ed5ef6bb3
Merge pull request #47773 from Roriz/feat/custom-header-direct-upload
Safe for Direct Uploads in js Libraries or Frameworks
2023-03-27 16:37:25 -04:00
Vipul A M
3d414f3986 Remove mini_mime usage in favour of marcel
We are using two libraries to do the same job. This commit removes the usage of mini_mime in favour of Marcel instead.

Changes are as follows:
- Replace MiniMime lookup by extension with Marcel Mimetype for lookup with extension
- Replaces usage of MiniMime lookup by content type to fetch extension with usage of Marcel Magic lookup. Marcel has multiple extentions being returned, we pick the first one. MiniMime always returns just one
- Removes specs which we specifically checking failing identification issue of MiniMine on jpeg images
- Removes mini_mime from gemspec
2023-03-27 23:24:43 +05:30
Radamés Roriz
26b209437b
lint: fix linter on changelog files 2023-03-26 15:51:00 -03:00
Radamés Roriz
896910fb7b
docs: change section to be more details about custom headers 2023-03-26 15:48:30 -03:00
Rafael Mendonça França
febd9ab4f6
Merge PR #47150 2023-03-25 16:55:06 +00:00
Matija Čupić
c0465cf6aa
Extract sample rate in audio analyzer 2023-03-23 19:50:32 +01:00
Rafael Mendonça França
18e53fbb2c
Remove deprecated purge and purge_later methods from the attachments association 2023-03-03 00:38:43 +00:00
Rafael Mendonça França
c720b7eba8
Remove deprecated behavior when assigning to a collection of attachments 2023-03-03 00:38:42 +00:00
Rafael Mendonça França
0591de55af
Remove deprecated ActiveStorage::Current#host and ActiveStorage::Current#host= methods 2023-03-03 00:38:41 +00:00
Rafael Mendonça França
4edaa4120b
Remove deprecated invalid default content types in Active Storage configurations 2023-03-03 00:38:40 +00:00
Shouichi Kamiya
98abeea7b6 Allow destroying active storage variant
Background:

When creating active storage variants, `ActiveStorage::VariantRecord` is
inserted, then a file is uploaded. Because upload can be failed, the
file can be missing even though `ActiveStorage::VariantRecord` exists.

When a file is missing, we need to delete the corresponding
`ActiveStorage::VariantRecord` but there's no API to delete just one
variant e.g., `blob.variant(resize_to_limit: [100, 100]).destroy`.

Co-authored-by: Yuichiro NAKAGAWA <ii.hsif.drows@gmail.com>
Co-authored-by: Ryohei UEDA <ueda@anipos.co.jp>
2023-02-08 18:36:45 +09:00
Chedli Bourguiba
0b8496fa7e Add preview to ActiveStorage::LogSubscriber
a `preview` event is being instrumented in `ActiveStorage::Previewer`. However it is not added inside ActiveStorage's `LogSubscriber` class.
2022-10-20 23:07:51 +02:00
Haroon Ahmed
206a826c8d Fix failing ActiveStorage test due to a change upstream in ffmpeg.
The original code which pulls the rotation from tags is still left for
older ffmpeg versions whilst the newer ffmpeg version 5.0+ will use the
side_data to retrieve the rotation info.
2022-08-26 15:25:53 +01:00
Nate Matykiewicz
294c271062
Touch model records after ActiveStorage::Blob is analyzed
This fixes a race condition where a record can be requested and have a
cache entry built, before the initial `analyze_later` completes, which
will not be invalidated until something else updates the record.

1. Upload attachment (this will create an ActiveStorage::Blob,
   ActiveStorage::Attachment, and touch the model)
2. Enqueue analyze job
3. Request record
4. Build a cache for that record
5. Analyze the attachment.
6. Request the record again
7. Serve a cache that doesn't include data from the analyzers, because
   the cache was built before it got analyzed, and the updated_at
   hasn't changed.

This also invalidates cache entries when a blob is re-analyzed, which
is helpful if a bug is fixed in an analyzer or a new analyzer is added.

Fixes #45567
2022-07-26 10:39:44 -05:00
Richard Böhme
acf767dbd6 Allow to use pre-defined variants for previews
Previously, named variants could only be used when calling the
`variant` method on an attachment. For files that are not `variable?`
but `previewable?` those pre-defined variants could not be used.

With this patch, the methods `preview` and `representation` also allow
to be passed a variation name as a symbol.

    class User < ActiveRecord::Base
      has_one_attached :file do |attachable|
        attachable.variant :thumb, resize_to_limit: [100, 100]
      end
    end

    <%= image_tag user.file.representation(:thumb) %>
2022-07-19 16:59:52 +02:00
Santiago Bartesaghi
7acdfcb12c Make ActiveStorage attach method be consistent between one and many 2022-06-20 19:17:07 -03:00
Santiago Bartesaghi
2895c6b9a2 Fix #41661 attaching multiple times within transaction
Co-authored-by: Abhay Nikam <nikam.abhay1@gmail.com>
Co-authored-by: Bruno Vezoli <brunvezoli@hotmail.com>
Co-authored-by: Juan Eduardo Roig <jeroig@gmail.com>
2022-06-06 21:23:33 -07:00
Ghouse Mohamed
06c83d93cf Added validation for global active storage service configuration 2022-05-31 08:36:46 -07:00
Felipe
e4eab9892f Fixes ActiveStorage proxy downloads of files over 5mb in S3-like storage services 2022-05-16 08:09:12 -03:00
Ghouse Mohamed
fbfb6e6885 Return blob/blobs when #attach is able to save the record and return if it is not able to 2022-02-26 02:18:51 +05:30
Abhay Nikam
5c7468dba8 Fixes active storage changelog entry(#44244) formatting [ci skip] 2022-01-28 16:32:56 +05:30