task(pj): create representations for latest pieces jointes

This commit is contained in:
Eric Leroy-Terquem 2024-06-11 17:30:09 +02:00
parent b638b2e45a
commit c94c2f55c8
No known key found for this signature in database
GPG key ID: ECE60B4C1FA2ABB3
4 changed files with 149 additions and 0 deletions

View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
module Maintenance
class CreatePreviewsForPjOfLatestDossiersTask < MaintenanceTasks::Task
def collection
dossier_ids = Dossier
.state_en_construction_ou_instruction
.where(depose_at: 3.months.ago..)
.pluck(:id)
champ_ids = Champ
.where(dossier_id: dossier_ids)
.where(type: ["Champs::PieceJustificativeChamp", 'Champs::TitreIdentiteChamp'])
.pluck(:id)
ActiveStorage::Attachment
.where(record_id: champ_ids)
end
def process(attachment)
return unless attachment.previewable?
attachment.preview(resize_to_limit: [400, 400]).processed unless attachment.preview(resize_to_limit: [400, 400]).image.attached?
rescue MiniMagick::Error
end
end
end

View file

@ -0,0 +1,29 @@
# frozen_string_literal: true
module Maintenance
class CreateVariantsForPjOfLatestDossiersTask < MaintenanceTasks::Task
def collection
dossier_ids = Dossier
.state_en_construction_ou_instruction
.where(depose_at: 3.months.ago..)
.pluck(:id)
champ_ids = Champ
.where(dossier_id: dossier_ids)
.where(type: ["Champs::PieceJustificativeChamp", 'Champs::TitreIdentiteChamp'])
.pluck(:id)
ActiveStorage::Attachment
.where(record_id: champ_ids)
end
def process(attachment)
return unless attachment.variable?
attachment.variant(resize_to_limit: [400, 400]).processed if attachment.variant(resize_to_limit: [400, 400]).key.nil?
if attachment.blob.content_type.in?(RARE_IMAGE_TYPES) && attachment.variant(resize_to_limit: [2000, 2000]).key.nil?
attachment.variant(resize_to_limit: [2000, 2000]).processed
end
rescue MiniMagick::Error
end
end
end