embeds_controller.rb 616 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class Api::Web::EmbedsController < Api::Web::BaseController
  3. before_action :require_user!
  4. def create
  5. status = StatusFinder.new(params[:url]).status
  6. return not_found if status.hidden?
  7. render json: status, serializer: OEmbedSerializer, width: 400
  8. rescue ActiveRecord::RecordNotFound
  9. oembed = FetchOEmbedService.new.call(params[:url])
  10. return not_found if oembed.nil?
  11. begin
  12. oembed[:html] = Sanitize.fragment(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
  13. rescue ArgumentError
  14. return not_found
  15. end
  16. render json: oembed
  17. end
  18. end