Add FASP account search support (#34033)
This commit is contained in:
		
					parent
					
						
							
								6d017dbf10
							
						
					
				
			
			
				commit
				
					
						ac4b735c67
					
				
			
		
					 8 changed files with 130 additions and 3 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| # frozen_string_literal: true | ||||
| 
 | ||||
| class Api::V2::SearchController < Api::BaseController | ||||
|   include AsyncRefreshesConcern | ||||
|   include Authorization | ||||
| 
 | ||||
|   RESULTS_LIMIT = 20 | ||||
|  | @ -13,6 +14,7 @@ class Api::V2::SearchController < Api::BaseController | |||
|     before_action :remote_resolve_error, if: :remote_resolve_requested? | ||||
|   end | ||||
|   before_action :require_valid_pagination_options! | ||||
|   before_action :handle_fasp_requests | ||||
| 
 | ||||
|   def index | ||||
|     @search = Search.new(search_results) | ||||
|  | @ -37,6 +39,21 @@ class Api::V2::SearchController < Api::BaseController | |||
|     render json: { error: 'Search queries that resolve remote resources are not supported without authentication' }, status: 401 | ||||
|   end | ||||
| 
 | ||||
|   def handle_fasp_requests | ||||
|     return unless Mastodon::Feature.fasp_enabled? | ||||
|     return if params[:q].blank? | ||||
| 
 | ||||
|     # Do not schedule a new retrieval if the request is a follow-up | ||||
|     # to an earlier retrieval | ||||
|     return if request.headers['Mastodon-Async-Refresh-Id'].present? | ||||
| 
 | ||||
|     refresh_key = "fasp:account_search:#{Digest::MD5.base64digest(params[:q])}" | ||||
|     return if AsyncRefresh.new(refresh_key).running? | ||||
| 
 | ||||
|     add_async_refresh_header(AsyncRefresh.create(refresh_key)) | ||||
|     @query_fasp = true | ||||
|   end | ||||
| 
 | ||||
|   def remote_resolve_requested? | ||||
|     truthy_param?(:resolve) | ||||
|   end | ||||
|  | @ -58,7 +75,8 @@ class Api::V2::SearchController < Api::BaseController | |||
|     search_params.merge( | ||||
|       resolve: truthy_param?(:resolve), | ||||
|       exclude_unreviewed: truthy_param?(:exclude_unreviewed), | ||||
|       following: truthy_param?(:following) | ||||
|       following: truthy_param?(:following), | ||||
|       query_fasp: @query_fasp | ||||
|     ) | ||||
|   end | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue