mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Merge pull request #7443 from rekonder/aj_SCI_10522
Improve handling of tinymce images for pdf reports [SCI-10522]
This commit is contained in:
commit
e0578778cf
3 changed files with 21 additions and 10 deletions
|
@ -29,7 +29,18 @@ module TinyMceImages
|
|||
)[0]
|
||||
next unless tm_asset_to_update
|
||||
|
||||
tm_asset_to_update.attributes['src'].value = tm_asset.convert_to_base64
|
||||
tm_asset = tm_asset.image.representation(resize_to_limit: Constants::LARGE_PIC_FORMAT).processed
|
||||
|
||||
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 = tm_asset.image.blob.metadata['width'].to_s
|
||||
height_attr.value = tm_asset.image.blob.metadata['height'].to_s
|
||||
end
|
||||
|
||||
tm_asset_to_update.attributes['src'].value = convert_to_base64(tm_asset.image)
|
||||
description = html_description.css('body').inner_html.to_s
|
||||
end
|
||||
description
|
||||
|
@ -221,5 +232,13 @@ module TinyMceImages
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def convert_to_base64(image)
|
||||
encoded_data = Base64.strict_encode64(image.download)
|
||||
"data:#{image.blob.content_type};base64,#{encoded_data}"
|
||||
rescue StandardError => e
|
||||
Rails.logger.error e.message
|
||||
"data:#{image.blob.content_type};base64,"
|
||||
end
|
||||
# rubocop:enable Metrics/BlockLength:
|
||||
end
|
||||
|
|
|
@ -203,14 +203,6 @@ class TinyMceAsset < ApplicationRecord
|
|||
image&.blob
|
||||
end
|
||||
|
||||
def convert_to_base64
|
||||
encoded_data = Base64.strict_encode64(image.download)
|
||||
"data:#{image.blob.content_type};base64,#{encoded_data}"
|
||||
rescue StandardError => e
|
||||
Rails.logger.error e.message
|
||||
"data:#{image.blob.content_type};base64,"
|
||||
end
|
||||
|
||||
def duplicate_file(to_asset)
|
||||
return unless image.attached?
|
||||
|
||||
|
|
|
@ -435,7 +435,7 @@ class Constants
|
|||
ASSET_SYNC_URL = ENV['ASSET_SYNC_URL'].freeze
|
||||
|
||||
# Grover timeout in ms
|
||||
GROVER_TIMEOUT_MS = 300000
|
||||
GROVER_TIMEOUT_MS = 450000
|
||||
|
||||
# SciNote Edit supported versions
|
||||
MIN_SCINOTE_EDIT_VERSION = ENV['MIN_SCINOTE_EDIT_VERSION'].freeze
|
||||
|
|
Loading…
Reference in a new issue