mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
30 lines
606 B
Ruby
30 lines
606 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Api
|
|
module V1
|
|
class ResultAssetSerializer < ActiveModel::Serializer
|
|
type :result_files
|
|
attributes :file_id, :file_name, :file_size, :url
|
|
|
|
def file_id
|
|
object.asset&.id
|
|
end
|
|
|
|
def file_name
|
|
object.asset&.file_name
|
|
end
|
|
|
|
def file_size
|
|
object.asset&.file_size
|
|
end
|
|
|
|
def url
|
|
if !object.asset&.file&.attached?
|
|
nil
|
|
else
|
|
Rails.application.routes.url_helpers.rails_blob_path(object.asset.file, disposition: 'attachment')
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|