mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Store previews in the same service as the original blob
This commit is contained in:
parent
ce5718aeef
commit
4203093ad3
7 changed files with 28 additions and 9 deletions
|
@ -1,3 +1,7 @@
|
|||
* Previews are created on the same service as the original blob.
|
||||
|
||||
*Peter Zhu*
|
||||
|
||||
* Remove unused `disposition` and `content_type` query parameters for `DiskService`.
|
||||
|
||||
*Peter Zhu*
|
||||
|
|
|
@ -74,7 +74,7 @@ class ActiveStorage::Preview
|
|||
end
|
||||
|
||||
def process
|
||||
previewer.preview do |attachable|
|
||||
previewer.preview(service_name: blob.service_name) do |attachable|
|
||||
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.writing_role) do
|
||||
image.attach(attachable)
|
||||
end
|
||||
|
|
|
@ -18,8 +18,9 @@ module ActiveStorage
|
|||
end
|
||||
|
||||
# Override this method in a concrete subclass. Have it yield an attachable preview image (i.e.
|
||||
# anything accepted by ActiveStorage::Attached::One#attach).
|
||||
def preview
|
||||
# anything accepted by ActiveStorage::Attached::One#attach). Pass the additional options to
|
||||
# the underlying blob that is created.
|
||||
def preview(**options)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
|
|
|
@ -20,10 +20,10 @@ module ActiveStorage
|
|||
end
|
||||
end
|
||||
|
||||
def preview
|
||||
def preview(**options)
|
||||
download_blob_to_tempfile do |input|
|
||||
draw_first_page_from input do |output|
|
||||
yield io: output, filename: "#{blob.filename.base}.png", content_type: "image/png"
|
||||
yield io: output, filename: "#{blob.filename.base}.png", content_type: "image/png", **options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,10 +18,10 @@ module ActiveStorage
|
|||
end
|
||||
end
|
||||
|
||||
def preview
|
||||
def preview(**options)
|
||||
download_blob_to_tempfile do |input|
|
||||
draw_first_page_from input do |output|
|
||||
yield io: output, filename: "#{blob.filename.base}.png", content_type: "image/png"
|
||||
yield io: output, filename: "#{blob.filename.base}.png", content_type: "image/png", **options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,10 +6,10 @@ module ActiveStorage
|
|||
blob.video?
|
||||
end
|
||||
|
||||
def preview
|
||||
def preview(**options)
|
||||
download_blob_to_tempfile do |input|
|
||||
draw_relevant_frame_from input do |output|
|
||||
yield io: output, filename: "#{blob.filename.base}.jpg", content_type: "image/jpeg"
|
||||
yield io: output, filename: "#{blob.filename.base}.jpg", content_type: "image/jpeg", **options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,4 +48,18 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase
|
|||
|
||||
assert blob.reload.preview_image.attached?
|
||||
end
|
||||
|
||||
test "preview of PDF is created on the same service" do
|
||||
blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf", service_name: "local_public")
|
||||
preview = blob.preview(resize: "640x280").processed
|
||||
|
||||
assert_equal "local_public", preview.image.blob.service_name
|
||||
end
|
||||
|
||||
test "preview of MP4 video is created on the same service" do
|
||||
blob = create_file_blob(filename: "video.mp4", content_type: "video/mp4", service_name: "local_public")
|
||||
preview = blob.preview(resize: "640x280").processed
|
||||
|
||||
assert_equal "local_public", preview.image.blob.service_name
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue