2019-05-30 14:35:16 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ProtocolImporters
|
|
|
|
module AttachmentsBuilder
|
2019-06-27 19:10:28 +08:00
|
|
|
def self.generate(step_json, user: nil, team: nil)
|
2019-05-30 14:35:16 +08:00
|
|
|
return [] unless step_json[:attachments]&.any?
|
|
|
|
|
|
|
|
step_json[:attachments].map do |f|
|
2019-09-12 23:21:48 +08:00
|
|
|
asset = Asset.new(created_by: user, last_modified_by: user, team: team)
|
2024-07-29 18:09:21 +08:00
|
|
|
asset.attach_file_version(io: URI.open(f[:url]), filename: f[:name])
|
2019-09-12 23:21:48 +08:00
|
|
|
asset
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
end
|
2019-06-27 19:10:28 +08:00
|
|
|
|
|
|
|
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
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
end
|