Move embed iframe page out of API

remove-old-upload-endpoint
Marcin Kulik 7 years ago
parent 3fcfe0ef30
commit ea28ebc5d9

@ -36,7 +36,6 @@
}
var apiHost = apiHostFromScript(script);
var apiUrl = apiHost + '/api';
var asciicastId = script.id.split('-')[1];
@ -52,7 +51,7 @@
insertAfter(script, container);
var iframe = document.createElement('iframe');
iframe.src = apiUrl + "/asciicasts/" + asciicastId + params(container, script);
iframe.src = apiHost + "/a/" + asciicastId + '/embed' + params(container, script);
iframe.id = "asciicast-iframe-" + asciicastId;
iframe.name = "asciicast-iframe-" + asciicastId;
iframe.scrolling = "no";

@ -1,11 +1,6 @@
module Api
class AsciicastsController < BaseController
before_filter :ensure_authenticated!, only: :create
respond_to :html, only: [:show]
attr_reader :asciicast
before_filter :ensure_authenticated!
def create
asciicast = asciicast_creator.create(asciicast_attributes)
@ -18,14 +13,6 @@ module Api
render text: e.message, status: 400
end
def show
@asciicast = Asciicast.find_by_id_or_secret_token!(params[:id])
allow_iframe_requests
render locals: {
page: BareAsciicastPagePresenter.build(asciicast, params)
}, layout: 'bare'
end
private
def asciicast_attributes
@ -35,10 +22,5 @@ module Api
def asciicast_creator
AsciicastCreator.new
end
def allow_iframe_requests
response.headers.delete('X-Frame-Options')
end
end
end

@ -33,6 +33,15 @@ class AsciicastsController < ApplicationController
end
end
def embed
asciicast = Asciicast.find_by_id_or_secret_token!(params[:id])
allow_iframe_requests
render locals: {
page: BareAsciicastPagePresenter.build(asciicast, params)
}, layout: 'embed'
end
def example
render layout: 'example'
end
@ -98,4 +107,8 @@ class AsciicastsController < ApplicationController
redirect_to url
end
end
def allow_iframe_requests
response.headers.delete('X-Frame-Options')
end
end

@ -7,7 +7,8 @@ Rails.application.routes.draw do
resources :asciicasts, path: 'a' do
member do
get '/raw' => 'api/asciicasts#show'
get '/raw' => 'asciicasts#embed' # legacy route, probably no longer used anywhere
get :embed
get :example
end
end
@ -18,7 +19,7 @@ Rails.application.routes.draw do
get "/oembed" => "oembed#show", as: :oembed
namespace :api do
resources :asciicasts
resources :asciicasts, only: [:create]
end
resource :login, only: [:new, :create] do

@ -37,7 +37,7 @@ describe "Asciicast retrieval" do
include Capybara::RSpecMatchers
before do
get "/api/asciicasts/#{asciicast.to_param}", format: 'html'
get "/a/#{asciicast.to_param}/embed", format: 'html'
end
it_behaves_like "asciicast iframe response"

@ -11,10 +11,10 @@ describe "asciicasts routing" do
end
# legacy route, kept for backwards compatibility with old embeds
it 'routes /a/1/raw to api/asciicasts#show' do
it 'routes /a/1/raw to asciicasts#embed' do
expect(get: '/a/1/raw').to route_to(
controller: 'api/asciicasts',
action: 'show',
controller: 'asciicasts',
action: 'embed',
id: '1',
)
end

Loading…
Cancel
Save