2014-03-05 09:05:45 +00:00
|
|
|
module Api
|
|
|
|
class AsciicastsController < BaseController
|
|
|
|
|
2015-04-04 17:48:01 +00:00
|
|
|
before_filter :ensure_authenticated!, only: :create
|
|
|
|
|
2014-12-23 17:27:33 +00:00
|
|
|
respond_to :html, only: [:show]
|
2014-03-05 09:05:45 +00:00
|
|
|
|
|
|
|
attr_reader :asciicast
|
|
|
|
|
|
|
|
def create
|
2015-02-27 14:38:18 +00:00
|
|
|
asciicast = asciicast_creator.create(asciicast_attributes)
|
2014-03-05 09:05:45 +00:00
|
|
|
render text: asciicast_url(asciicast), status: :created,
|
|
|
|
location: asciicast
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
2015-03-02 19:41:25 +00:00
|
|
|
render text: e.record.errors.messages, status: 422
|
2015-03-23 16:40:11 +00:00
|
|
|
rescue AsciicastParams::FormatError => e
|
|
|
|
render text: e.message, status: 400
|
2014-03-05 09:05:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2015-04-26 13:30:42 +00:00
|
|
|
@asciicast = Asciicast.find_by_id_or_secret_token!(params[:id])
|
2014-10-19 11:25:51 +00:00
|
|
|
|
2014-03-05 09:05:45 +00:00
|
|
|
respond_with(asciicast) do |format|
|
|
|
|
format.html do
|
2014-03-16 10:34:25 +00:00
|
|
|
allow_iframe_requests
|
2014-03-05 09:05:45 +00:00
|
|
|
render locals: {
|
|
|
|
page: BareAsciicastPagePresenter.build(asciicast, params)
|
|
|
|
}, layout: 'bare'
|
|
|
|
end
|
2015-05-13 13:10:03 +00:00
|
|
|
|
|
|
|
format.json do
|
2016-01-07 13:41:25 +00:00
|
|
|
render json: asciicast, v0: params[:v0]
|
2015-05-13 13:10:03 +00:00
|
|
|
end
|
2014-03-05 09:05:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-02-27 14:38:18 +00:00
|
|
|
def asciicast_attributes
|
2015-04-03 16:48:37 +00:00
|
|
|
AsciicastParams.build(params[:asciicast], current_user, request.user_agent)
|
2015-02-27 13:58:04 +00:00
|
|
|
end
|
|
|
|
|
2014-03-05 09:05:45 +00:00
|
|
|
def asciicast_creator
|
|
|
|
AsciicastCreator.new
|
|
|
|
end
|
|
|
|
|
2014-03-16 10:34:25 +00:00
|
|
|
def allow_iframe_requests
|
|
|
|
response.headers.delete('X-Frame-Options')
|
|
|
|
end
|
|
|
|
|
2014-03-05 09:05:45 +00:00
|
|
|
end
|
|
|
|
end
|