embeds_controller.rb 848 B

123456789101112131415161718192021222324252627282930313233343536
  1. # frozen_string_literal: true
  2. class Api::Web::EmbedsController < Api::Web::BaseController
  3. include Authorization
  4. before_action :set_status
  5. def show
  6. return not_found if @status.hidden?
  7. if @status.local?
  8. render json: @status, serializer: OEmbedSerializer, width: 400
  9. else
  10. return not_found unless user_signed_in?
  11. url = ActivityPub::TagManager.instance.url_for(@status)
  12. oembed = FetchOEmbedService.new.call(url)
  13. return not_found if oembed.nil?
  14. begin
  15. oembed[:html] = Sanitize.fragment(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
  16. rescue ArgumentError
  17. return not_found
  18. end
  19. render json: oembed
  20. end
  21. end
  22. def set_status
  23. @status = Status.find(params[:id])
  24. authorize @status, :show?
  25. rescue Mastodon::NotPermittedError
  26. not_found
  27. end
  28. end