You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
Ruby
47 lines
1.1 KiB
Ruby
class AsciicastParams
|
|
|
|
def self.build(params, user_agent)
|
|
meta = JSON.parse(params[:meta].read)
|
|
|
|
attributes = {
|
|
stdout_data: params[:stdout],
|
|
stdout_timing: params[:stdout_timing],
|
|
stdin_data: params[:stdin],
|
|
stdin_timing: params[:stdin_timing],
|
|
username: meta['username'],
|
|
duration: meta['duration'],
|
|
title: meta['title'],
|
|
command: meta['command'],
|
|
shell: meta['shell'],
|
|
terminal_lines: meta['term']['lines'],
|
|
terminal_columns: meta['term']['columns'],
|
|
terminal_type: meta['term']['type'],
|
|
}
|
|
|
|
if meta['uname']
|
|
attributes[:uname] = meta['uname']
|
|
else
|
|
attributes[:user_agent] = user_agent
|
|
end
|
|
|
|
assign_user_or_token(attributes, meta)
|
|
|
|
attributes
|
|
end
|
|
|
|
def self.assign_user_or_token(attributes, meta)
|
|
token = meta['user_token']
|
|
|
|
if token.present?
|
|
api_token = ApiToken.find_by_token(token)
|
|
|
|
if api_token
|
|
attributes[:user_id] = api_token.user_id
|
|
else
|
|
attributes[:api_token] = token
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|