logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

web_finger_controller.ex (1310B)


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