Resolve follow activity from accept/reject without ID (#328)
[akkoma] / lib / pleroma / web / web_finger / web_finger_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.WebFinger.WebFingerController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Web.WebFinger
9
10 plug(Pleroma.Web.Plugs.SetFormatPlug)
11 plug(Pleroma.Web.Plugs.FederatingPlug)
12
13 def host_meta(conn, _params) do
14 xml = WebFinger.host_meta()
15
16 conn
17 |> put_resp_content_type("application/xrd+xml")
18 |> send_resp(200, xml)
19 end
20
21 def webfinger(%{assigns: %{format: format}} = conn, %{"resource" => resource})
22 when format in ["xml", "xrd+xml"] do
23 with {:ok, response} <- WebFinger.webfinger(resource, "XML") do
24 conn
25 |> put_resp_content_type("application/xrd+xml")
26 |> send_resp(200, response)
27 else
28 _e -> send_resp(conn, 404, "Couldn't find user")
29 end
30 end
31
32 def webfinger(%{assigns: %{format: format}} = conn, %{"resource" => resource})
33 when format in ["json", "jrd+json"] do
34 with {:ok, response} <- WebFinger.webfinger(resource, "JSON") do
35 json(conn, response)
36 else
37 _e ->
38 conn
39 |> put_status(404)
40 |> json("Couldn't find user")
41 end
42 end
43
44 def webfinger(conn, _params), do: send_resp(conn, 400, "Bad Request")
45 end