2018-09-13 16:37:21 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ResultAssetSerializer < ActiveModel::Serializer
|
2018-10-07 18:36:58 +08:00
|
|
|
type :result_files
|
|
|
|
attributes :file_id, :file_name, :file_size, :url
|
|
|
|
|
|
|
|
def file_id
|
|
|
|
object.asset&.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_name
|
2019-07-09 16:28:15 +08:00
|
|
|
object.asset&.file_name
|
2018-10-07 18:36:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def file_size
|
2019-07-09 16:28:15 +08:00
|
|
|
object.asset&.file_size
|
2018-10-07 18:36:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2019-07-26 21:58:51 +08:00
|
|
|
if !object.asset&.file&.attached?
|
2018-10-07 18:36:58 +08:00
|
|
|
nil
|
|
|
|
else
|
2019-07-26 21:58:51 +08:00
|
|
|
Rails.application.routes.url_helpers.rails_blob_path(object.asset.file, disposition: 'attachment')
|
2018-10-07 18:36:58 +08:00
|
|
|
end
|
|
|
|
end
|
2018-09-13 16:37:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|