feat(gallery): display large variant for rare image types
This commit is contained in:
parent
f3795ebc98
commit
05ad5dcbd6
6 changed files with 33 additions and 9 deletions
|
@ -38,6 +38,9 @@ class ImageProcessorJob < ApplicationJob
|
||||||
blob.attachments.each do |attachment|
|
blob.attachments.each do |attachment|
|
||||||
next unless attachment&.representable?
|
next unless attachment&.representable?
|
||||||
attachment.representation(resize_to_limit: [400, 400]).processed
|
attachment.representation(resize_to_limit: [400, 400]).processed
|
||||||
|
if attachment.blob.content_type.in?(RARE_IMAGE_TYPES)
|
||||||
|
attachment.variant(resize_to_limit: [2000, 2000]).processed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
|
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
|
||||||
|
|
||||||
- elsif blob.variable? && blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
|
- elsif blob.variable? && blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
|
||||||
= link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
|
- blob_url = blob.content_type.in?(RARE_IMAGE_TYPES) ? attachment.variant(resize_to_limit: [2000, 2000]).processed.url : blob.url
|
||||||
|
= link_to image_url(blob_url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
|
||||||
.thumbnail
|
.thumbnail
|
||||||
= image_tag(attachment.variant(resize_to_limit: [400, 400]).processed.url, loading: :lazy)
|
= image_tag(attachment.variant(resize_to_limit: [400, 400]).processed.url, loading: :lazy)
|
||||||
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
= 'Visualiser'
|
= 'Visualiser'
|
||||||
|
|
||||||
- elsif blob.variable? && blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
|
- elsif blob.variable? && blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
|
||||||
= link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
|
- blob_url = blob.content_type.in?(RARE_IMAGE_TYPES) ? attachment.variant(resize_to_limit: [2000, 2000]).processed.url : blob.url
|
||||||
|
= link_to image_url(blob_url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
|
||||||
.thumbnail
|
.thumbnail
|
||||||
= image_tag(attachment.variant(resize_to_limit: [400, 400]).processed.url, loading: :lazy)
|
= image_tag(attachment.variant(resize_to_limit: [400, 400]).processed.url, loading: :lazy)
|
||||||
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
||||||
|
|
|
@ -15,6 +15,10 @@ AUTHORIZED_IMAGE_TYPES = [
|
||||||
'image/vnd.dwg' # multimedia x 137 auto desk
|
'image/vnd.dwg' # multimedia x 137 auto desk
|
||||||
]
|
]
|
||||||
|
|
||||||
|
RARE_IMAGE_TYPES = [
|
||||||
|
'image/tiff' # multimedia x 3985
|
||||||
|
]
|
||||||
|
|
||||||
AUTHORIZED_CONTENT_TYPES = AUTHORIZED_IMAGE_TYPES + AUTHORIZED_PDF_TYPES + [
|
AUTHORIZED_CONTENT_TYPES = AUTHORIZED_IMAGE_TYPES + AUTHORIZED_PDF_TYPES + [
|
||||||
# multimedia
|
# multimedia
|
||||||
'video/mp4', # multimedia x 2075
|
'video/mp4', # multimedia x 2075
|
||||||
|
|
BIN
spec/fixtures/files/pencil.tiff
vendored
Normal file
BIN
spec/fixtures/files/pencil.tiff
vendored
Normal file
Binary file not shown.
|
@ -63,7 +63,6 @@ describe ImageProcessorJob, type: :job do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'create representation' do
|
describe 'create representation' do
|
||||||
let(:file) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
|
|
||||||
let(:blob_info) do
|
let(:blob_info) do
|
||||||
{
|
{
|
||||||
filename: file.original_filename,
|
filename: file.original_filename,
|
||||||
|
@ -81,19 +80,35 @@ describe ImageProcessorJob, type: :job do
|
||||||
blob
|
blob
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when representation is not required" do
|
context "when type image is usual" do
|
||||||
it "it does not create blob representation" do
|
let(:file) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
|
||||||
expect { described_class.perform_now(blob) }.not_to change { ActiveStorage::VariantRecord.count }
|
|
||||||
|
context "when representation is not required" do
|
||||||
|
it "it does not create blob representation" do
|
||||||
|
expect { described_class.perform_now(blob) }.not_to change { ActiveStorage::VariantRecord.count }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when representation is required" do
|
||||||
|
before do
|
||||||
|
allow(blob).to receive(:representation_required?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "it creates blob representation" do
|
||||||
|
expect { described_class.perform_now(blob) }.to change { ActiveStorage::VariantRecord.count }.by(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when representation is required" do
|
context "when type image is rare" do
|
||||||
|
let(:file) { fixture_file_upload('spec/fixtures/files/pencil.tiff', 'image/tiff') }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(blob).to receive(:representation_required?).and_return(true)
|
allow(blob).to receive(:representation_required?).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "it creates blob representation" do
|
it "creates a second variant" do
|
||||||
expect { described_class.perform_now(blob) }.to change { ActiveStorage::VariantRecord.count }.by(1)
|
expect { described_class.perform_now(blob) }.to change { ActiveStorage::VariantRecord.count }.by(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue