diff --git a/app/assets/javascripts/protocols/import_export/import.js b/app/assets/javascripts/protocols/import_export/import.js index e439dcac2..74fa9baac 100644 --- a/app/assets/javascripts/protocols/import_export/import.js +++ b/app/assets/javascripts/protocols/import_export/import.js @@ -500,7 +500,14 @@ function importProtocolFromFile( var tinyMceAsset = {}; var fileRef = $(this).attr('fileRef'); tinyMceAsset.tokenId = $(this).attr('tokenId'); + tinyMceAsset.fileName = $(this).children('fileName').text(); tinyMceAsset.fileType = $(this).children('fileType').text(); + if ($(this).children('fileMetadata').html() !== undefined) { + tinyMceAsset.fileMetadata = $(this).children('fileMetadata').html() + .replace('', '') + .replace(']]>', ''); + } tinyMceAsset.bytes = getAssetBytes( protocolFolders[index], stepGuid, @@ -579,6 +586,12 @@ function importProtocolFromFile( stepAssetJson.id = assetId; stepAssetJson.fileName = fileName; stepAssetJson.fileType = $(this).children('fileType').text(); + if ($(this).children('fileMetadata').html() !== undefined) { + stepAssetJson.fileMetadata = $(this).children('fileMetadata').html() + .replace('', '') + .replace(']]>', ''); + } stepAssetJson.bytes = getAssetBytes( protocolFolders[index], stepGuid, diff --git a/app/models/tiny_mce_asset.rb b/app/models/tiny_mce_asset.rb index 4178192b7..edf5d234a 100644 --- a/app/models/tiny_mce_asset.rb +++ b/app/models/tiny_mce_asset.rb @@ -138,10 +138,9 @@ class TinyMceAsset < ApplicationRecord if exists? order(:id).each do |tiny_mce_asset| asset_guid = get_guid(tiny_mce_asset.id) - asset_file_name = "rte-#{asset_guid.to_s + tiny_mce_asset.image.blob.filename.extension}" + asset_file_name = "rte-#{asset_guid}.#{tiny_mce_asset.image.blob.filename.extension}" ostream.put_next_entry("#{dir}/#{asset_file_name}") ostream.print(tiny_mce_asset.image.download) - input_file.close end end ostream diff --git a/app/utilities/protocols_exporter.rb b/app/utilities/protocols_exporter.rb index f63d31246..1c05dfa02 100644 --- a/app/utilities/protocols_exporter.rb +++ b/app/utilities/protocols_exporter.rb @@ -56,6 +56,7 @@ module ProtocolsExporter "fileRef=\"#{asset_file_name}\">\n" asset_xml << "#{img.file_name}\n" asset_xml << "#{img.content_type}\n" + asset_xml << "\n" asset_xml << "\n" tiny_assets_xml << asset_xml end @@ -104,6 +105,7 @@ module ProtocolsExporter "fileRef=\"#{asset_file_name}\">\n" asset_xml << "#{asset.file_name}\n" asset_xml << "#{asset.content_type}\n" + asset_xml << "\n" asset_xml << "\n" step_xml << asset_xml end diff --git a/app/utilities/protocols_importer.rb b/app/utilities/protocols_importer.rb index 00726582d..0cdffb505 100644 --- a/app/utilities/protocols_importer.rb +++ b/app/utilities/protocols_importer.rb @@ -111,7 +111,10 @@ module ProtocolsImporter ) # Decode the file bytes - asset.file.attach(io: StringIO.new(Base64.decode64(asset_json['bytes'])), filename: asset_json['fileName']) + asset.file.attach(io: StringIO.new(Base64.decode64(asset_json['bytes'])), + filename: asset_json['fileName'], + content_type: asset_json['fileType'], + metadata: JSON.parse(asset_json['fileMetadata'] || '{}')) asset.save! asset_ids << asset.id @@ -153,8 +156,11 @@ module ProtocolsImporter tiny_mce_img.save! # Decode the file bytes - tiny_mce_img.image.attach(io: StringIO.new(Base64.decode64(tiny_mce_img_json['bytes'])), - filename: tiny_mce_img_json['fileName']) + file = StringIO.new(Base64.decode64(tiny_mce_img_json['bytes'])) + tiny_mce_img.image.attach(io: file, + filename: tiny_mce_img_json['fileName'], + content_type: tiny_mce_img_json['fileType'], + metadata: JSON.parse(tiny_mce_img_json['fileMetadata'] || '{}')) if description.gsub!("data-mce-token=\"#{tiny_mce_img_json['tokenId']}\"", "data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"") else