mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-21 11:17:09 +08:00
Fix protocol import of eln files with attached images [SCI-12110] (#8645)
This commit is contained in:
parent
943acf037e
commit
c3aa3cc53e
1 changed files with 6 additions and 20 deletions
|
@ -60,7 +60,6 @@ class ProtocolsImporterV2
|
||||||
protocol.description = populate_rte(protocol_json, protocol)
|
protocol.description = populate_rte(protocol_json, protocol)
|
||||||
protocol.name = protocol_json['name'].presence
|
protocol.name = protocol_json['name'].presence
|
||||||
protocol.save!
|
protocol.save!
|
||||||
asset_ids = []
|
|
||||||
step_pos = 0
|
step_pos = 0
|
||||||
|
|
||||||
# Check if protocol has steps
|
# Check if protocol has steps
|
||||||
|
@ -92,44 +91,31 @@ class ProtocolsImporterV2
|
||||||
|
|
||||||
next unless step_json['assets']
|
next unless step_json['assets']
|
||||||
|
|
||||||
asset_ids += create_assets(step_json, step)
|
create_assets(step_json, step)
|
||||||
end
|
|
||||||
|
|
||||||
# Post process assets
|
|
||||||
asset_ids.each do |asset_id|
|
|
||||||
Asset.find(asset_id).post_process_file
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_assets(step_json, step)
|
def create_assets(step_json, step)
|
||||||
asset_ids = []
|
|
||||||
step_json['assets']&.values&.each do |asset_json|
|
step_json['assets']&.values&.each do |asset_json|
|
||||||
asset = Asset.new(
|
asset = Asset.create!(
|
||||||
created_by: @user,
|
created_by: @user,
|
||||||
last_modified_by: @user,
|
last_modified_by: @user,
|
||||||
team: @team
|
team: @team,
|
||||||
|
step: step
|
||||||
)
|
)
|
||||||
|
|
||||||
# Decode the file bytes
|
# Decode the file bytes
|
||||||
asset.attach_file_version(io: StringIO.new(Base64.decode64(asset_json['bytes'])),
|
asset.attach_file_version(io: StringIO.new(Base64.decode64(asset_json['bytes'])),
|
||||||
filename: asset_json['fileName'],
|
filename: asset_json['fileName'],
|
||||||
content_type: asset_json['fileType'],
|
content_type: asset_json['fileType'],
|
||||||
metadata: JSON.parse(asset_json['fileMetadata'] || '{}'))
|
metadata: JSON.parse(asset_json['fileMetadata'] || '{}').except('created_by_id'))
|
||||||
if asset_json['preview_image'].present?
|
if asset_json['preview_image'].present?
|
||||||
asset.preview_image.attach(io: StringIO.new(Base64.decode64(asset_json.dig('preview_image', 'bytes'))),
|
asset.preview_image.attach(io: StringIO.new(Base64.decode64(asset_json.dig('preview_image', 'bytes'))),
|
||||||
filename: asset_json.dig('preview_image', 'fileName'))
|
filename: asset_json.dig('preview_image', 'fileName'))
|
||||||
end
|
end
|
||||||
|
|
||||||
asset.save!
|
asset.post_process_file
|
||||||
asset_ids << asset.id
|
|
||||||
|
|
||||||
StepAsset.create!(
|
|
||||||
step: step,
|
|
||||||
asset: asset
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
asset_ids
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_step_text(step, params)
|
def create_step_text(step, params)
|
||||||
|
|
Loading…
Add table
Reference in a new issue