From 37a018880b4d4add48e18ee7201e989ba907c515 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 29 Aug 2024 17:30:23 +0200 Subject: [PATCH] chore: generate representations coming from ActionText in background --- app/jobs/image_processor_job.rb | 3 ++ .../concerns/blob_image_processor_concern.rb | 6 +++- app/views/active_storage/blobs/_blob.html.erb | 29 +++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/jobs/image_processor_job.rb b/app/jobs/image_processor_job.rb index 230db3344..16b76f32d 100644 --- a/app/jobs/image_processor_job.rb +++ b/app/jobs/image_processor_job.rb @@ -58,6 +58,9 @@ class ImageProcessorJob < ApplicationJob if attachment.blob.content_type.in?(RARE_IMAGE_TYPES) attachment.variant(resize_to_limit: [2000, 2000]).processed end + if attachment.record.class == ActionText::RichText + attachment.variant(resize_to_limit: [1024, 768]).processed + end end end diff --git a/app/models/concerns/blob_image_processor_concern.rb b/app/models/concerns/blob_image_processor_concern.rb index 63fac2365..08d6f1067 100644 --- a/app/models/concerns/blob_image_processor_concern.rb +++ b/app/models/concerns/blob_image_processor_concern.rb @@ -10,7 +10,7 @@ module BlobImageProcessorConcern end def representation_required? - from_champ? || from_messagerie? || is_a_logo? + from_champ? || from_messagerie? || logo? || from_action_text? end private @@ -27,6 +27,10 @@ module BlobImageProcessorConcern attachments.any? { _1.name == 'logo' } end + def from_action_text? + attachments.any? { _1.record.class == ActionText::RichText } + end + def watermark_required? attachments.any? { _1.record.class == Champs::TitreIdentiteChamp } end diff --git a/app/views/active_storage/blobs/_blob.html.erb b/app/views/active_storage/blobs/_blob.html.erb index 49ba357dd..8e95058a4 100644 --- a/app/views/active_storage/blobs/_blob.html.erb +++ b/app/views/active_storage/blobs/_blob.html.erb @@ -1,14 +1,19 @@ -
attachment--<%= blob.filename.extension %>"> - <% if blob.representable? %> - <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> - <% end %> - -
- <% if caption = blob.try(:caption) %> - <%= caption %> +<% if blob.representable? %> + <% representation = blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> + <% if representation.image&.attached? || representation.key.present? %> +
+ <%= image_tag representation %> <% else %> - <%= blob.filename %> - <%= number_to_human_size blob.byte_size %> +
+ <%= image_tag blob %> <% end %> -
-
+ +
+ <% if caption = blob.try(:caption) %> + <%= caption %> + <% else %> + <%= blob.filename %> + <%= number_to_human_size blob.byte_size %> + <% end %> +
+<% end %>