diff --git a/app/models/asset.rb b/app/models/asset.rb index 851d18038..87aeb32c9 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -8,6 +8,11 @@ class Asset < ApplicationRecord include ActiveStorageFileUtil include ActiveStorageConcerns + attr_accessor :file_file_name + attr_accessor :file_file_size + attr_accessor :file_content_type + attr_accessor :file_updated_at + require 'tempfile' # Lock duration set to 30 minutes LOCK_DURATION = 60 * 30 diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 65c6fe8e8..5e62f4f0c 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -2,6 +2,11 @@ class Experiment < ApplicationRecord include ArchivableModel include SearchableModel include SearchableByNameModel + attr_accessor :workflowimg_file_name + attr_accessor :workflowimg_file_size + attr_accessor :workflowimg_content_type + attr_accessor :workflowimg_updated_at + belongs_to :project, inverse_of: :experiments, touch: true belongs_to :created_by, diff --git a/app/models/step.rb b/app/models/step.rb index ec8d3960a..600921c09 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -127,7 +127,7 @@ class Step < ApplicationRecord end def asset_position(asset) - assets.order(:file_updated_at).each_with_index do |step_asset, i| + assets.order(:updated_at).each_with_index do |step_asset, i| return { count: assets.count, pos: i } if asset.id == step_asset.id end end diff --git a/app/services/model_exporters/model_exporter.rb b/app/services/model_exporters/model_exporter.rb index 38975ec79..a4e88424a 100644 --- a/app/services/model_exporters/model_exporter.rb +++ b/app/services/model_exporters/model_exporter.rb @@ -15,22 +15,15 @@ module ModelExporters def copy_files(assets, attachment_name, dir_name) assets.flatten.each do |a| next unless a.public_send(attachment_name).attached? + blob = a.public_send(attachment_name).blob + dir = FileUtils.mkdir_p(File.join(dir_name, a.id.to_s)).first + destination_path = File.join(dir, a.file_name) + + blob.open do |file| + FileUtils.cp(file.path, destination_path) + end yield if block_given? - dir = FileUtils.mkdir_p(File.join(dir_name, a.id.to_s)).first - - tempfile = Tempfile.new - tempfile.binmode - a.public_send(attachment_name).blob.download { |chunk| tempfile.write(chunk) } - tempfile.flush - tempfile.rewind - FileUtils.cp( - tempfile.path, - File.join(dir, a.file_name) - ) - ensure - tempfile.close - tempfile.unlink end end