2017-08-31 11:38:35 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-17 23:23:46 +10:00
|
|
|
class Api::Web::EmbedsController < Api::Web::BaseController
|
2023-07-13 23:53:03 +10:00
|
|
|
include Authorization
|
2017-08-31 11:38:35 +10:00
|
|
|
|
2023-07-13 23:53:03 +10:00
|
|
|
before_action :set_status
|
2020-02-08 01:24:22 +11:00
|
|
|
|
2023-07-13 23:53:03 +10:00
|
|
|
def show
|
|
|
|
return not_found if @status.hidden?
|
2020-02-08 01:24:22 +11:00
|
|
|
|
2023-07-13 23:53:03 +10:00
|
|
|
if @status.local?
|
2024-09-20 22:39:48 +10:00
|
|
|
render json: @status, serializer: OEmbedSerializer
|
2023-07-13 23:53:03 +10:00
|
|
|
else
|
|
|
|
return not_found unless user_signed_in?
|
2018-05-03 02:58:48 +10:00
|
|
|
|
2023-07-13 23:53:03 +10:00
|
|
|
url = ActivityPub::TagManager.instance.url_for(@status)
|
|
|
|
oembed = FetchOEmbedService.new.call(url)
|
|
|
|
return not_found if oembed.nil?
|
2020-02-08 01:24:22 +11:00
|
|
|
|
2023-07-13 23:53:03 +10:00
|
|
|
begin
|
|
|
|
oembed[:html] = Sanitize.fragment(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
|
|
|
|
rescue ArgumentError
|
|
|
|
return not_found
|
|
|
|
end
|
|
|
|
|
|
|
|
render json: oembed
|
2018-05-03 02:58:48 +10:00
|
|
|
end
|
2023-07-13 23:53:03 +10:00
|
|
|
end
|
2020-02-08 01:24:22 +11:00
|
|
|
|
2023-07-13 23:53:03 +10:00
|
|
|
def set_status
|
|
|
|
@status = Status.find(params[:id])
|
|
|
|
authorize @status, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2017-08-31 11:38:35 +10:00
|
|
|
end
|
|
|
|
end
|