69ec27ba05f1979ebeab7b040aab23bde9b82a29
[akkoma] / lib / pleroma / web / nodeinfo / nodeinfo_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.Nodeinfo.NodeinfoController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Web.Endpoint
9 alias Pleroma.Web.Nodeinfo.Nodeinfo
10
11 def schemas(conn, _params) do
12 response = %{
13 links: [
14 %{
15 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
16 href: Endpoint.url() <> "/nodeinfo/2.0.json"
17 },
18 %{
19 rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
20 href: Endpoint.url() <> "/nodeinfo/2.1.json"
21 }
22 ]
23 }
24
25 json(conn, response)
26 end
27
28 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
29 # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
30 def nodeinfo(conn, %{"version" => version}) do
31 case Nodeinfo.get_nodeinfo(version) do
32 {:error, :missing} ->
33 render_error(conn, :not_found, "Nodeinfo schema version not handled")
34
35 node_info ->
36 conn
37 |> put_resp_header(
38 "content-type",
39 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
40 )
41 |> json(node_info)
42 end
43 end
44 end