mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 21:36:44 +08:00
Add metadata for .eln assets (#1942)
This commit is contained in:
parent
2fae7d8208
commit
4fe0227d8c
4 changed files with 25 additions and 5 deletions
|
@ -500,7 +500,14 @@ function importProtocolFromFile(
|
||||||
var tinyMceAsset = {};
|
var tinyMceAsset = {};
|
||||||
var fileRef = $(this).attr('fileRef');
|
var fileRef = $(this).attr('fileRef');
|
||||||
tinyMceAsset.tokenId = $(this).attr('tokenId');
|
tinyMceAsset.tokenId = $(this).attr('tokenId');
|
||||||
|
tinyMceAsset.fileName = $(this).children('fileName').text();
|
||||||
tinyMceAsset.fileType = $(this).children('fileType').text();
|
tinyMceAsset.fileType = $(this).children('fileType').text();
|
||||||
|
if ($(this).children('fileMetadata').html() !== undefined) {
|
||||||
|
tinyMceAsset.fileMetadata = $(this).children('fileMetadata').html()
|
||||||
|
.replace('<!--[CDATA[', '')
|
||||||
|
.replace(' ]]-->', '')
|
||||||
|
.replace(']]>', '');
|
||||||
|
}
|
||||||
tinyMceAsset.bytes = getAssetBytes(
|
tinyMceAsset.bytes = getAssetBytes(
|
||||||
protocolFolders[index],
|
protocolFolders[index],
|
||||||
stepGuid,
|
stepGuid,
|
||||||
|
@ -579,6 +586,12 @@ function importProtocolFromFile(
|
||||||
stepAssetJson.id = assetId;
|
stepAssetJson.id = assetId;
|
||||||
stepAssetJson.fileName = fileName;
|
stepAssetJson.fileName = fileName;
|
||||||
stepAssetJson.fileType = $(this).children('fileType').text();
|
stepAssetJson.fileType = $(this).children('fileType').text();
|
||||||
|
if ($(this).children('fileMetadata').html() !== undefined) {
|
||||||
|
stepAssetJson.fileMetadata = $(this).children('fileMetadata').html()
|
||||||
|
.replace('<!--[CDATA[', '')
|
||||||
|
.replace(' ]]-->', '')
|
||||||
|
.replace(']]>', '');
|
||||||
|
}
|
||||||
stepAssetJson.bytes = getAssetBytes(
|
stepAssetJson.bytes = getAssetBytes(
|
||||||
protocolFolders[index],
|
protocolFolders[index],
|
||||||
stepGuid,
|
stepGuid,
|
||||||
|
|
|
@ -138,10 +138,9 @@ class TinyMceAsset < ApplicationRecord
|
||||||
if exists?
|
if exists?
|
||||||
order(:id).each do |tiny_mce_asset|
|
order(:id).each do |tiny_mce_asset|
|
||||||
asset_guid = get_guid(tiny_mce_asset.id)
|
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.put_next_entry("#{dir}/#{asset_file_name}")
|
||||||
ostream.print(tiny_mce_asset.image.download)
|
ostream.print(tiny_mce_asset.image.download)
|
||||||
input_file.close
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ostream
|
ostream
|
||||||
|
|
|
@ -56,6 +56,7 @@ module ProtocolsExporter
|
||||||
"fileRef=\"#{asset_file_name}\">\n"
|
"fileRef=\"#{asset_file_name}\">\n"
|
||||||
asset_xml << "<fileName>#{img.file_name}</fileName>\n"
|
asset_xml << "<fileName>#{img.file_name}</fileName>\n"
|
||||||
asset_xml << "<fileType>#{img.content_type}</fileType>\n"
|
asset_xml << "<fileType>#{img.content_type}</fileType>\n"
|
||||||
|
asset_xml << "<fileMetadata><!--[CDATA[ #{img.image.metadata.to_json} ]]--></fileMetadata>\n"
|
||||||
asset_xml << "</tinyMceAsset>\n"
|
asset_xml << "</tinyMceAsset>\n"
|
||||||
tiny_assets_xml << asset_xml
|
tiny_assets_xml << asset_xml
|
||||||
end
|
end
|
||||||
|
@ -104,6 +105,7 @@ module ProtocolsExporter
|
||||||
"fileRef=\"#{asset_file_name}\">\n"
|
"fileRef=\"#{asset_file_name}\">\n"
|
||||||
asset_xml << "<fileName>#{asset.file_name}</fileName>\n"
|
asset_xml << "<fileName>#{asset.file_name}</fileName>\n"
|
||||||
asset_xml << "<fileType>#{asset.content_type}</fileType>\n"
|
asset_xml << "<fileType>#{asset.content_type}</fileType>\n"
|
||||||
|
asset_xml << "<fileMetadata><!--[CDATA[ #{asset.file.metadata.to_json} ]]--></fileMetadata>\n"
|
||||||
asset_xml << "</asset>\n"
|
asset_xml << "</asset>\n"
|
||||||
step_xml << asset_xml
|
step_xml << asset_xml
|
||||||
end
|
end
|
||||||
|
|
|
@ -111,7 +111,10 @@ module ProtocolsImporter
|
||||||
)
|
)
|
||||||
|
|
||||||
# Decode the file bytes
|
# 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.save!
|
||||||
asset_ids << asset.id
|
asset_ids << asset.id
|
||||||
|
|
||||||
|
@ -153,8 +156,11 @@ module ProtocolsImporter
|
||||||
tiny_mce_img.save!
|
tiny_mce_img.save!
|
||||||
|
|
||||||
# Decode the file bytes
|
# Decode the file bytes
|
||||||
tiny_mce_img.image.attach(io: StringIO.new(Base64.decode64(tiny_mce_img_json['bytes'])),
|
file = StringIO.new(Base64.decode64(tiny_mce_img_json['bytes']))
|
||||||
filename: tiny_mce_img_json['fileName'])
|
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']}\"",
|
if description.gsub!("data-mce-token=\"#{tiny_mce_img_json['tokenId']}\"",
|
||||||
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"")
|
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"")
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue