Merge pull request #7793 from artoscinote/ma_SCI_10970

Don't fail report if a TinyMCE image variant fails to generate [SCI-10970]
This commit is contained in:
Martin Artnik 2024-08-12 12:31:57 +02:00 committed by GitHub
commit 0b059899b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,19 +29,24 @@ module TinyMceImages
)[0]
next unless tm_asset_to_update
variant = tm_asset.image.variant(resize_to_limit: Constants::LARGE_PIC_FORMAT)
resized_asset = ActiveStorage::Variant.new(variant.blob, variant.variation).processed
begin
variant = tm_asset.image.variant(resize_to_limit: Constants::LARGE_PIC_FORMAT)
resized_asset = ActiveStorage::Variant.new(variant.blob, variant.variation).processed
width_attr = tm_asset_to_update.attributes['width']
height_attr = tm_asset_to_update.attributes['height']
width_attr = tm_asset_to_update.attributes['width']
height_attr = tm_asset_to_update.attributes['height']
if width_attr && height_attr && (width_attr.value.to_i >= Constants::LARGE_PIC_FORMAT[0] ||
height_attr.value.to_i >= Constants::LARGE_PIC_FORMAT[1])
width_attr.value = resized_asset.image.blob.metadata['width'].to_s
height_attr.value = resized_asset.image.blob.metadata['height'].to_s
if width_attr && height_attr && (width_attr.value.to_i >= Constants::LARGE_PIC_FORMAT[0] ||
height_attr.value.to_i >= Constants::LARGE_PIC_FORMAT[1])
width_attr.value = resized_asset.image.blob.metadata['width'].to_s
height_attr.value = resized_asset.image.blob.metadata['height'].to_s
end
tm_asset_to_update.attributes['src'].value = convert_to_base64(resized_asset)
rescue StandardError => e
Rails.logger.error(e)
end
tm_asset_to_update.attributes['src'].value = convert_to_base64(resized_asset)
description = html_description.css('body').inner_html.to_s
end
description