mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-30 20:23:14 +08:00
26 lines
646 B
Ruby
26 lines
646 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ProtocolImporters
|
|
module AttachmentsBuilder
|
|
def self.generate(step_json, user: nil, team: nil)
|
|
return [] unless step_json[:attachments]&.any?
|
|
|
|
step_json[:attachments].map do |f|
|
|
asset = Asset.new(created_by: user, last_modified_by: user, team: team)
|
|
asset.file.attach(io: URI.open(f[:url]), filename: f[:name])
|
|
asset
|
|
end
|
|
end
|
|
|
|
def self.generate_json(step_json)
|
|
return [] unless step_json[:attachments]&.any?
|
|
|
|
step_json[:attachments].map do |f|
|
|
{
|
|
name: f[:name],
|
|
url: f[:url]
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|