You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
600 B

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