2013-09-20 21:21:25 +00:00
|
|
|
class AsciicastSerializer < ActiveModel::Serializer
|
|
|
|
self.root = false
|
2013-08-13 17:49:48 +00:00
|
|
|
|
2016-01-11 15:14:46 +00:00
|
|
|
attributes :id, :url, :snapshot, :width, :height
|
2015-04-26 15:09:30 +00:00
|
|
|
|
2015-05-13 10:43:49 +00:00
|
|
|
def id
|
|
|
|
object.to_param
|
|
|
|
end
|
|
|
|
|
2015-12-22 17:40:20 +00:00
|
|
|
def url
|
2016-01-07 13:41:25 +00:00
|
|
|
if v0_url?
|
2015-12-22 17:40:20 +00:00
|
|
|
object.stdout_frames_url
|
|
|
|
else
|
2016-04-10 15:12:35 +00:00
|
|
|
url = object.data.url
|
|
|
|
if url.starts_with?("/")
|
|
|
|
asciicast_path(object, format: :json) # download URL for local carrierwave store
|
|
|
|
else
|
|
|
|
url # direct signed S3 URL (because XHR CORS redirect doesn't work under Safari)
|
|
|
|
end
|
2015-12-22 17:40:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 15:09:30 +00:00
|
|
|
def private?
|
|
|
|
object.private?
|
|
|
|
end
|
|
|
|
|
2015-10-08 09:55:14 +00:00
|
|
|
def title
|
|
|
|
object.title
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_display_name
|
|
|
|
object.user.display_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_url
|
|
|
|
object.user.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_avatar_url
|
|
|
|
object.user.avatar_url(object.user)
|
|
|
|
end
|
|
|
|
|
2015-12-22 17:40:20 +00:00
|
|
|
private
|
|
|
|
|
2016-01-07 13:41:25 +00:00
|
|
|
def v0_url?
|
|
|
|
!!@options[:v0]
|
2015-12-22 17:40:20 +00:00
|
|
|
end
|
|
|
|
|
2013-08-13 17:49:48 +00:00
|
|
|
end
|