2013-09-25 17:29:57 +00:00
|
|
|
class AsciicastParams
|
|
|
|
|
2013-10-11 18:44:49 +00:00
|
|
|
def initialize(params, headers)
|
|
|
|
@params = params
|
|
|
|
@headers = headers
|
2013-09-25 17:29:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_h
|
|
|
|
attributes = {
|
2013-10-11 18:44:49 +00:00
|
|
|
:stdout_data => params[:stdout],
|
|
|
|
:stdout_timing => params[:stdout_timing],
|
|
|
|
:stdin_data => params[:stdin],
|
|
|
|
:stdin_timing => params[:stdin_timing],
|
2013-09-25 17:29:57 +00:00
|
|
|
:username => meta['username'],
|
|
|
|
:duration => meta['duration'],
|
|
|
|
:recorded_at => meta['recorded_at'],
|
|
|
|
:title => meta['title'],
|
|
|
|
:command => meta['command'],
|
|
|
|
:shell => meta['shell'],
|
|
|
|
:terminal_lines => meta['term']['lines'],
|
|
|
|
:terminal_columns => meta['term']['columns'],
|
|
|
|
:terminal_type => meta['term']['type'],
|
|
|
|
}
|
|
|
|
|
2013-10-13 10:29:30 +00:00
|
|
|
if meta['uname']
|
|
|
|
attributes[:uname] = meta['uname']
|
|
|
|
else
|
|
|
|
attributes[:user_agent] = headers['User-Agent']
|
|
|
|
end
|
|
|
|
|
2013-09-25 17:29:57 +00:00
|
|
|
assign_user_or_token(attributes, meta)
|
|
|
|
|
|
|
|
attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2013-10-11 18:44:49 +00:00
|
|
|
attr_reader :params, :headers
|
2013-09-25 17:29:57 +00:00
|
|
|
|
|
|
|
def meta
|
2013-10-11 18:44:49 +00:00
|
|
|
@meta ||= JSON.parse(params[:meta].read)
|
2013-09-25 17:29:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def assign_user_or_token(attributes, meta)
|
|
|
|
token = meta['user_token']
|
|
|
|
|
|
|
|
if token.present?
|
|
|
|
user_token = UserToken.find_by_token(token)
|
|
|
|
|
|
|
|
if user_token
|
|
|
|
attributes[:user_id] = user_token.user_id
|
|
|
|
else
|
|
|
|
attributes[:user_token] = token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|