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.

40 lines
768 B

  1. # frozen_string_literal: true
  2. class Api::V1::SearchController < Api::BaseController
  3. include Authorization
  4. RESULTS_LIMIT = 5
  5. before_action -> { doorkeeper_authorize! :read, :'read:search' }
  6. before_action :require_user!
  7. respond_to :json
  8. def index
  9. @search = Search.new(search)
  10. render json: @search, serializer: REST::SearchSerializer
  11. end
  12. private
  13. def search
  14. search_results.tap do |search|
  15. search[:statuses].keep_if do |status|
  16. begin
  17. authorize status, :show?
  18. rescue Mastodon::NotPermittedError
  19. false
  20. end
  21. end
  22. end
  23. end
  24. def search_results
  25. SearchService.new.call(
  26. params[:q],
  27. RESULTS_LIMIT,
  28. truthy_param?(:resolve),
  29. current_account
  30. )
  31. end
  32. end