2013-09-25 17:29:57 +00:00
|
|
|
class AsciicastParams
|
|
|
|
|
2014-02-10 16:39:37 +00:00
|
|
|
def self.build(params, user_agent)
|
2014-02-09 18:12:15 +00:00
|
|
|
meta = JSON.parse(params[:meta].read)
|
2013-09-25 17:29:57 +00:00
|
|
|
|
|
|
|
attributes = {
|
2014-02-09 13:58:17 +00:00
|
|
|
command: meta['command'],
|
2014-02-11 16:49:22 +00:00
|
|
|
duration: meta['duration'],
|
2014-02-09 13:58:17 +00:00
|
|
|
shell: meta['shell'],
|
2014-02-11 16:49:22 +00:00
|
|
|
stdin_data: params[:stdin],
|
|
|
|
stdin_timing: params[:stdin_timing],
|
|
|
|
stdout_data: params[:stdout],
|
|
|
|
stdout_timing: params[:stdout_timing],
|
2014-02-09 13:58:17 +00:00
|
|
|
terminal_columns: meta['term']['columns'],
|
2014-02-11 16:49:22 +00:00
|
|
|
terminal_lines: meta['term']['lines'],
|
2014-02-09 13:58:17 +00:00
|
|
|
terminal_type: meta['term']['type'],
|
2014-02-11 16:49:22 +00:00
|
|
|
title: meta['title'],
|
|
|
|
user: get_user(meta)
|
2013-09-25 17:29:57 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 16:49:22 +00:00
|
|
|
if meta['uname'] # old client, with useless, random user_agent
|
2013-10-13 10:29:30 +00:00
|
|
|
attributes[:uname] = meta['uname']
|
|
|
|
else
|
2014-02-10 16:39:37 +00:00
|
|
|
attributes[:user_agent] = user_agent
|
2013-10-13 10:29:30 +00:00
|
|
|
end
|
|
|
|
|
2014-02-10 16:39:37 +00:00
|
|
|
attributes
|
2013-09-25 17:29:57 +00:00
|
|
|
end
|
|
|
|
|
2014-02-11 16:49:22 +00:00
|
|
|
def self.get_user(attributes)
|
2014-02-15 20:37:05 +00:00
|
|
|
token = attributes['user_token']
|
|
|
|
username = attributes['username']
|
|
|
|
|
|
|
|
User.for_api_token(token) || User.create_dummy(token, username)
|
2013-09-25 17:29:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|