Support downloading asciicast JSON file as "attachment"
This commit is contained in:
parent
e29f755cbc
commit
b8f90166c1
@ -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
|
||||
end
|
||||
opts = if params[:dl]
|
||||
{ query: { "response-content-disposition" => "attachment; filename=#{asciicast.download_filename}" } }
|
||||
else
|
||||
{}
|
||||
end
|
||||
|
||||
redirect_to asciicast.data_url(opts)
|
||||
end
|
||||
|
||||
format.png do
|
||||
|
@ -85,8 +85,12 @@ class Asciicast < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def data_url
|
||||
file_url || stdout_frames_url
|
||||
def data_url(options = {})
|
||||
file_url(options) || stdout_frames_url(options)
|
||||
end
|
||||
|
||||
def download_filename
|
||||
"asciicast-#{id}.json"
|
||||
end
|
||||
|
||||
def stdout
|
||||
|
@ -13,7 +13,7 @@ class AsciicastSerializer < ActiveModel::Serializer
|
||||
if v0_url?
|
||||
object.stdout_frames_url
|
||||
else
|
||||
object.data_url
|
||||
asciicast_path(object, format: :json)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -13,7 +13,7 @@ describe AsciicastSerializer do
|
||||
end
|
||||
|
||||
it 'includes url' do
|
||||
expect(subject['url']).to eq(asciicast.file_url)
|
||||
expect(subject['url']).to eq("/a/#{asciicast.to_param}.json")
|
||||
end
|
||||
|
||||
it 'includes snapshot' do
|
||||
|
Loading…
Reference in New Issue
Block a user