2018-08-07 20:19:49 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class RepositoryAssetValueSerializer < ActiveModel::Serializer
|
|
|
|
attributes :file_id, :file_name, :file_size, :url
|
|
|
|
|
2021-08-18 16:00:01 +08:00
|
|
|
include TimestampableModel
|
|
|
|
|
2018-08-07 20:19:49 +08:00
|
|
|
def file_id
|
|
|
|
object.asset&.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_name
|
2019-07-09 16:28:15 +08:00
|
|
|
object.asset&.file_name
|
2018-08-07 20:19:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def file_size
|
2019-07-09 16:28:15 +08:00
|
|
|
object.asset&.file_size
|
2018-08-07 20:19:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2019-07-26 21:58:51 +08:00
|
|
|
if !object.asset&.file&.attached?
|
2018-08-07 20:19:49 +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-08-07 20:19:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|