mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Merge pull request #1943 from aignatov-bio/ai-sci-3629-add-metadata-to-protocol-repository-import-export
Fix protocol copy, add metadata to assets [SCI-3629]
This commit is contained in:
commit
f0b7771e19
4 changed files with 21 additions and 6 deletions
|
@ -241,7 +241,7 @@ class Asset < ApplicationRecord
|
|||
download_blob_to_tempfile do |tmp_file|
|
||||
to_asset.file.attach(io: tmp_file.open, filename: file_name)
|
||||
end
|
||||
new_asset.post_process_file(new_asset.team)
|
||||
to_asset.post_process_file(to_asset.team)
|
||||
end
|
||||
|
||||
def extract_image_quality
|
||||
|
|
|
@ -73,7 +73,7 @@ module TinyMceImages
|
|||
|
||||
tiny_img_clone.transaction do
|
||||
tiny_img_clone.save!
|
||||
tiny_img_clone.image.attach(io: tiny_img.image.open, filename: tiny_img.image.filename.to_s)
|
||||
tiny_img.duplicate_file(tiny_img_clone)
|
||||
end
|
||||
|
||||
target.tiny_mce_assets << tiny_img_clone
|
||||
|
@ -96,8 +96,6 @@ module TinyMceImages
|
|||
|
||||
next if asset && asset.object == self && asset.team_id != asset_team_id
|
||||
|
||||
new_image = asset.image
|
||||
new_image_filename = new_image.file_name
|
||||
else
|
||||
# We need implement size and type checks here
|
||||
new_image = URI.parse(image['src']).open
|
||||
|
@ -111,7 +109,11 @@ module TinyMceImages
|
|||
|
||||
new_asset.transaction do
|
||||
new_asset.save!
|
||||
new_asset.image.attach(io: new_image, filename: new_image_filename)
|
||||
if image['data-mce-token']
|
||||
asset.duplicate_file(new_asset)
|
||||
else
|
||||
new_asset.image.attach(io: new_image, filename: new_image_filename)
|
||||
end
|
||||
end
|
||||
|
||||
image['src'] = ''
|
||||
|
|
|
@ -302,6 +302,7 @@ class Protocol < ApplicationRecord
|
|||
step.assets.each do |asset|
|
||||
asset2 = asset.dup
|
||||
asset2.save!
|
||||
asset.duplicate_file(asset2)
|
||||
step2.assets << asset2
|
||||
assets_to_clone << [asset.id, asset2.id]
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TinyMceAsset < ApplicationRecord
|
||||
include ActiveStorage::Downloading
|
||||
extend ProtocolsExporter
|
||||
attr_accessor :reference
|
||||
before_create :set_reference, optional: true
|
||||
|
@ -170,7 +171,7 @@ class TinyMceAsset < ApplicationRecord
|
|||
|
||||
tiny_img_clone.transaction do
|
||||
tiny_img_clone.save!
|
||||
tiny_img_clone.image.attach(io: image.download, filename: image.filename.sanitized)
|
||||
duplicate_file(tiny_img_clone)
|
||||
end
|
||||
|
||||
return false unless tiny_img_clone.persisted?
|
||||
|
@ -188,6 +189,17 @@ class TinyMceAsset < ApplicationRecord
|
|||
obj.reassign_tiny_mce_image_references(cloned_img_ids)
|
||||
end
|
||||
|
||||
def blob
|
||||
image&.blob
|
||||
end
|
||||
|
||||
def duplicate_file(to_asset)
|
||||
download_blob_to_tempfile do |tmp_file|
|
||||
to_asset.image.attach(io: tmp_file.open, filename: file_name)
|
||||
end
|
||||
TinyMceAsset.update_estimated_size(to_asset.id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self_destruct
|
||||
|
|
Loading…
Reference in a new issue