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
|
|
|
|
|
|
|
|
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
|
2018-10-29 01:39:34 +08:00
|
|
|
if !object.asset&.file&.exists?
|
2018-08-07 20:19:49 +08:00
|
|
|
nil
|
|
|
|
else
|
2019-07-05 22:56:05 +08:00
|
|
|
rails_blob_path(object.asset.file, disposition: 'attachment')
|
2018-08-07 20:19:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|