2016-12-01 09:01:03 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-08 04:09:25 +10:00
|
|
|
class Api::OEmbedController < Api::BaseController
|
2020-01-14 18:52:32 +11:00
|
|
|
skip_before_action :require_authenticated_user!
|
|
|
|
|
2020-01-24 10:20:51 +11:00
|
|
|
before_action :set_status
|
|
|
|
before_action :require_public_status!
|
|
|
|
|
2016-12-01 09:01:03 +11:00
|
|
|
def show
|
2017-08-30 18:23:43 +10:00
|
|
|
render json: @status, serializer: OEmbedSerializer, width: maxwidth_or_default, height: maxheight_or_default
|
2016-12-01 09:01:03 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-01-24 10:20:51 +11:00
|
|
|
def set_status
|
|
|
|
@status = status_finder.status
|
|
|
|
end
|
|
|
|
|
|
|
|
def require_public_status!
|
|
|
|
not_found if @status.hidden?
|
|
|
|
end
|
|
|
|
|
2017-08-30 18:23:43 +10:00
|
|
|
def status_finder
|
|
|
|
StatusFinder.new(params[:url])
|
2017-04-27 22:42:22 +10:00
|
|
|
end
|
|
|
|
|
2017-05-31 06:30:06 +10:00
|
|
|
def maxwidth_or_default
|
|
|
|
(params[:maxwidth].presence || 400).to_i
|
2017-04-27 22:42:22 +10:00
|
|
|
end
|
|
|
|
|
2017-05-31 06:30:06 +10:00
|
|
|
def maxheight_or_default
|
|
|
|
params[:maxheight].present? ? params[:maxheight].to_i : nil
|
2016-12-01 09:01:03 +11:00
|
|
|
end
|
|
|
|
end
|