asciinema.org/app/models/asciicast_params.rb

38 lines
1.0 KiB
Ruby
Raw Normal View History

class AsciicastParams
def self.build(params, user_agent)
2014-02-09 18:12:15 +00:00
meta = JSON.parse(params[:meta].read)
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)
}
2014-02-11 16:49:22 +00:00
if meta['uname'] # old client, with useless, random user_agent
attributes[:uname] = meta['uname']
else
attributes[:user_agent] = user_agent
end
attributes
end
2014-02-11 16:49:22 +00:00
def self.get_user(attributes)
token = attributes['user_token']
username = attributes['username']
User.for_api_token(token) || User.create_dummy(token, username)
end
end