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.

25 lines
626 B

  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] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
  13. rescue ArgumentError
  14. return not_found
  15. end
  16. render json: oembed
  17. end
  18. end