]> cat aescling's git repositories - mastodon.git/blob - app/controllers/api/v1/search_controller.rb
Update AUTHORS.md (#9141)
[mastodon.git] / app / controllers / api / v1 / search_controller.rb
1 # frozen_string_literal: true
2
3 class Api::V1::SearchController < Api::BaseController
4 include Authorization
5
6 RESULTS_LIMIT = 5
7
8 before_action -> { doorkeeper_authorize! :read, :'read:search' }
9 before_action :require_user!
10
11 respond_to :json
12
13 def index
14 @search = Search.new(search)
15 render json: @search, serializer: REST::SearchSerializer
16 end
17
18 private
19
20 def search
21 search_results.tap do |search|
22 search[:statuses].keep_if do |status|
23 begin
24 authorize status, :show?
25 rescue Mastodon::NotPermittedError
26 false
27 end
28 end
29 end
30 end
31
32 def search_results
33 SearchService.new.call(
34 params[:q],
35 RESULTS_LIMIT,
36 truthy_param?(:resolve),
37 current_account
38 )
39 end
40 end
This page took 0.076017 seconds and 4 git commands to generate.