]> cat aescling's git repositories - mastodon.git/commitdiff
Add `GET /api/v1/accounts/lookup` REST API (#15740)
authorEugen Rochko <eugen@zeonfederated.com>
Tue, 16 Feb 2021 14:28:32 +0000 (15:28 +0100)
committerGitHub <noreply@github.com>
Tue, 16 Feb 2021 14:28:32 +0000 (15:28 +0100)
app/controllers/api/v1/accounts/lookup_controller.rb [new file with mode: 0644]
config/routes.rb

diff --git a/app/controllers/api/v1/accounts/lookup_controller.rb b/app/controllers/api/v1/accounts/lookup_controller.rb
new file mode 100644 (file)
index 0000000..aee6be1
--- /dev/null
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class Api::V1::Accounts::LookupController < Api::BaseController
+  before_action -> { authorize_if_got_token! :read, :'read:accounts' }
+  before_action :set_account
+
+  def show
+    render json: @account, serializer: REST::AccountSerializer
+  end
+
+  private
+
+  def set_account
+    @account = ResolveAccountService.new.call(params[:acct], skip_webfinger: true) || raise(ActiveRecord::RecordNotFound)
+  end
+end
index a534b433e07de9796a33636314b99e945b8ed3f5..fd118f1d61d7ed67641c3fc3339ae315257f28bb 100644 (file)
@@ -431,6 +431,7 @@ Rails.application.routes.draw do
         get :verify_credentials, to: 'credentials#show'
         patch :update_credentials, to: 'credentials#update'
         resource :search, only: :show, controller: :search
+        resource :lookup, only: :show, controller: :lookup
         resources :relationships, only: :index
       end