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
|
|
|
|
object.asset&.file_file_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_size
|
|
|
|
object.asset&.file_file_size
|
|
|
|
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
|
|
|
|
elsif object.asset&.file&.is_stored_on_s3?
|
|
|
|
object.asset.presigned_url(download: true)
|
|
|
|
else
|
2018-10-10 23:00:53 +08:00
|
|
|
object.asset.file.url
|
2018-08-07 20:19:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|