The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

28 lines
646 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. return not_found if status.hidden?
  8. render json: status, serializer: OEmbedSerializer, width: 400
  9. rescue ActiveRecord::RecordNotFound
  10. oembed = FetchOEmbedService.new.call(params[:url])
  11. return not_found if oembed.nil?
  12. begin
  13. oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
  14. rescue ArgumentError
  15. return not_found
  16. end
  17. render json: oembed
  18. end
  19. end