remote_interaction API endpoint
authormarcin mikołajczak <git@mkljczk.pl>
Mon, 22 Nov 2021 18:44:30 +0000 (19:44 +0100)
committermarcin mikołajczak <git@mkljczk.pl>
Thu, 2 Dec 2021 15:08:44 +0000 (16:08 +0100)
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
lib/pleroma/web/api_spec/operations/twitter_util_operation.ex
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/controllers/util_controller.ex

index ebcfd3be231e661871a1409147331bf8fd228875..1a2dbb16652446fa258986e444f90d46c6b82344 100644 (file)
@@ -237,4 +237,30 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do
       responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
     }
   end
+
+  def remote_interaction_operation do
+    %Operation{
+      tags: ["Accounts"],
+      summary: "Remote interaction",
+      operationId: "UtilController.remote_interaction",
+      requestBody: request_body("Parameters", remote_interaction_request(), required: true),
+      responses: %{
+        200 =>
+          Operation.response("Remote interaction URL", "application/json", %Schema{type: :object})
+      }
+    }
+  end
+
+  defp remote_interaction_request do
+    %Schema{
+      title: "RemoteInteractionRequest",
+      description: "POST body for remote interaction",
+      type: :object,
+      required: [:ap_id, :profile],
+      properties: %{
+        ap_id: %Schema{type: :string, description: "Profile or status ActivityPub ID"},
+        profile: %Schema{type: :string, description: "Remote profile webfinger"}
+      }
+    }
+  end
 end
index abb332ec2f1f9eed9b232f83fa34f50b0fa7b654..f8bafd3c2c30961902ea3fc2af0a97acbb30445a 100644 (file)
@@ -150,6 +150,7 @@ defmodule Pleroma.Web.Router do
     get("/emoji", UtilController, :emoji)
     get("/captcha", UtilController, :captcha)
     get("/healthcheck", UtilController, :healthcheck)
+    post("/remote_interaction", UtilController, :remote_interaction)
   end
 
   scope "/api/v1/pleroma", Pleroma.Web do
index ef43f76820637cb8b44da7d423dc3ae288f4f4ed..cbcef7475353ea20fe3e9f7160dad686e0e1d076 100644 (file)
@@ -62,6 +62,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
     end
   end
 
+  def remote_interaction(%{body_params: %{ap_id: ap_id, profile: profile}} = conn, _params) do
+    with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile) do
+      conn
+      |> json(%{url: String.replace(template, "{uri}", ap_id)})
+    else
+      _e -> json(conn, %{error: "Couldn't find user"})
+    end
+  end
+
   def frontend_configurations(conn, _params) do
     render(conn, "frontend_configurations.json")
   end