asciinema.org/app/services/asciicast_creator.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

class AsciicastCreator
def create(attributes)
attributes = prepare_attributes(attributes)
2013-08-25 14:34:02 +00:00
options = { :without_protection => true }
2013-08-25 14:34:02 +00:00
Asciicast.create!(attributes, options).tap do |asciicast|
SnapshotWorker.perform_async(asciicast.id)
end
end
private
def prepare_attributes(attributes)
meta = parse_meta_file(attributes[:meta])
{
:stdout_data => attributes[:stdout],
:stdout_timing => attributes[:stdout_timing],
:stdin_data => attributes[:stdin],
:stdin_timing => attributes[:stdin_timing],
:username => meta['username'],
:user_token => meta['user_token'],
:duration => meta['duration'],
:recorded_at => meta['recorded_at'],
:title => meta['title'],
:command => meta['command'],
:shell => meta['shell'],
:uname => meta['uname'],
:terminal_lines => meta['term']['lines'],
:terminal_columns => meta['term']['columns'],
:terminal_type => meta['term']['type'],
}
end
def parse_meta_file(file)
JSON.parse(file.read)
end
end