Play v1 format by default if available
This commit is contained in:
parent
4da03be774
commit
e3c04e1461
@ -5,8 +5,7 @@ function tryCreatePlayer(parentNode, asciicast, options) {
|
||||
asciinema_player.core.CreatePlayer(
|
||||
parentNode,
|
||||
asciicast.width, asciicast.height,
|
||||
asciicast.stdout_frames_url,
|
||||
asciicast.duration,
|
||||
asciicast.url,
|
||||
{
|
||||
snapshot: asciicast.snapshot,
|
||||
speed: options.speed,
|
||||
@ -31,7 +30,7 @@ function tryCreatePlayer(parentNode, asciicast, options) {
|
||||
}
|
||||
|
||||
function checkReadiness() {
|
||||
if (asciicast.stdout_frames_url) {
|
||||
if (asciicast.url && asciicast.snapshot) {
|
||||
$('.processing-info').remove();
|
||||
createPlayer();
|
||||
} else {
|
||||
|
@ -30,7 +30,7 @@ module Api
|
||||
end
|
||||
|
||||
format.json do
|
||||
render json: asciicast
|
||||
render json: asciicast, playback_options: PlaybackOptions.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,10 @@
|
||||
module AsciicastsHelper
|
||||
|
||||
def player(asciicast, options = PlaybackOptions.new, skip_titlebar = false)
|
||||
render 'asciicasts/player', asciicast: AsciicastSerializer.new(asciicast),
|
||||
options: options,
|
||||
skip_titlebar: skip_titlebar
|
||||
render 'asciicasts/player',
|
||||
asciicast: AsciicastSerializer.new(asciicast, playback_options: options),
|
||||
options: options,
|
||||
skip_titlebar: skip_titlebar
|
||||
end
|
||||
|
||||
def screenshot_javascript_tag
|
||||
|
@ -85,6 +85,10 @@ class Asciicast < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def data_url
|
||||
file_url || stdout_frames_url
|
||||
end
|
||||
|
||||
def stdout
|
||||
return @stdout if @stdout
|
||||
@stdout = Stdout::Buffered.new(get_stdout)
|
||||
|
@ -20,6 +20,7 @@ class PlaybackOptions
|
||||
attribute :benchmark, Boolean, default: false
|
||||
attribute :theme, String, default: Theme::DEFAULT
|
||||
attribute :t, Time
|
||||
attribute :v0, Boolean, default: false
|
||||
|
||||
def as_json(*)
|
||||
opts = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
class AsciicastSerializer < ActiveModel::Serializer
|
||||
self.root = false
|
||||
|
||||
attributes :id, :duration, :stdout_frames_url, :snapshot
|
||||
attributes :id, :url, :snapshot
|
||||
attribute :terminal_columns, key: :width
|
||||
attribute :terminal_lines, key: :height
|
||||
|
||||
@ -9,6 +9,14 @@ class AsciicastSerializer < ActiveModel::Serializer
|
||||
object.to_param
|
||||
end
|
||||
|
||||
def url
|
||||
if playback_options.v0
|
||||
object.stdout_frames_url
|
||||
else
|
||||
object.data_url
|
||||
end
|
||||
end
|
||||
|
||||
def private?
|
||||
object.private?
|
||||
end
|
||||
@ -29,4 +37,10 @@ class AsciicastSerializer < ActiveModel::Serializer
|
||||
object.user.avatar_url(object.user)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def playback_options
|
||||
@options[:playback_options]
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
||||
|
||||
describe AsciicastSerializer do
|
||||
|
||||
let(:serializer) { described_class.new(asciicast) }
|
||||
let(:serializer) { AsciicastSerializer.new(asciicast, playback_options: PlaybackOptions.new) }
|
||||
let(:asciicast) { create(:asciicast) }
|
||||
|
||||
describe '#to_json' do
|
||||
@ -12,12 +12,8 @@ describe AsciicastSerializer do
|
||||
expect(subject['id']).to eq(asciicast.to_param)
|
||||
end
|
||||
|
||||
it 'includes duration' do
|
||||
expect(subject['duration']).to eq(asciicast.duration)
|
||||
end
|
||||
|
||||
it 'includes stdout_frames_url' do
|
||||
expect(subject['stdout_frames_url']).to eq(asciicast.stdout_frames_url)
|
||||
it 'includes url' do
|
||||
expect(subject['url']).to eq(asciicast.file_url)
|
||||
end
|
||||
|
||||
it 'includes snapshot' do
|
||||
|
1481
vendor/assets/javascripts/asciinema-player.js
vendored
1481
vendor/assets/javascripts/asciinema-player.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user