@ -28,11 +28,13 @@ class AsciicastsController < ApplicationController
end
format.json do
if url = asciicast.file_url
redirect_to url
else
render nothing: true, status: 404
opts = if params[:dl]
{ query: { "response-content-disposition" => "attachment; filename=#{asciicast.download_filename}" } }
{}
redirect_to asciicast.data_url(opts)
format.png do
@ -85,8 +85,12 @@ class Asciicast < ActiveRecord::Base
def data_url
file_url || stdout_frames_url
def data_url(options = {})
file_url(options) || stdout_frames_url(options)
def download_filename
"asciicast-#{id}.json"
def stdout
@ -13,7 +13,7 @@ class AsciicastSerializer < ActiveModel::Serializer
if v0_url?
object.stdout_frames_url
object.data_url
asciicast_path(object, format: :json)
@ -13,7 +13,7 @@ describe AsciicastSerializer do
it 'includes url' do
expect(subject['url']).to eq(asciicast.file_url)
expect(subject['url']).to eq("/a/#{asciicast.to_param}.json")
it 'includes snapshot' do