Merge branch 'add-node-info-2.0-support' into 'master'
Add NodeInfo 2.0 support (in addition to 2.1) See merge request framasoft/mobilizon!155
This commit is contained in:
commit
33a8da4570
@ -7,37 +7,42 @@ defmodule MobilizonWeb.NodeInfoController do
|
|||||||
use MobilizonWeb, :controller
|
use MobilizonWeb, :controller
|
||||||
|
|
||||||
alias Mobilizon.{Events, Users}
|
alias Mobilizon.{Events, Users}
|
||||||
|
alias Mobilizon.CommonConfig
|
||||||
|
|
||||||
@instance Application.get_env(:mobilizon, :instance)
|
@instance Application.get_env(:mobilizon, :instance)
|
||||||
|
@node_info_supported_versions ["2.0", "2.1"]
|
||||||
|
@node_info_schema_uri "http://nodeinfo.diaspora.software/ns/schema/"
|
||||||
|
|
||||||
def schemas(conn, _params) do
|
def schemas(conn, _params) do
|
||||||
response = %{
|
links =
|
||||||
links: [
|
@node_info_supported_versions
|
||||||
|
|> Enum.map(fn version ->
|
||||||
%{
|
%{
|
||||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
|
rel: @node_info_schema_uri <> version,
|
||||||
href: MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, "2.1")
|
href:
|
||||||
}
|
MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, version)
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
json(conn, response)
|
json(conn, %{
|
||||||
|
links: links
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
|
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
|
||||||
def nodeinfo(conn, %{"version" => "2.1"}) do
|
def nodeinfo(conn, %{"version" => version}) when version in @node_info_supported_versions do
|
||||||
response = %{
|
response = %{
|
||||||
version: "2.1",
|
version: version,
|
||||||
software: %{
|
software: %{
|
||||||
name: "mobilizon",
|
name: "mobilizon",
|
||||||
version: Keyword.get(@instance, :version),
|
version: Keyword.get(@instance, :version)
|
||||||
repository: Keyword.get(@instance, :repository)
|
|
||||||
},
|
},
|
||||||
protocols: ["activitypub"],
|
protocols: ["activitypub"],
|
||||||
services: %{
|
services: %{
|
||||||
inbound: [],
|
inbound: [],
|
||||||
outbound: []
|
outbound: ["atom1.0"]
|
||||||
},
|
},
|
||||||
openRegistrations: Keyword.get(@instance, :registrations_open),
|
openRegistrations: CommonConfig.registrations_open?(),
|
||||||
usage: %{
|
usage: %{
|
||||||
users: %{
|
users: %{
|
||||||
total: Users.count_users()
|
total: Users.count_users()
|
||||||
@ -46,10 +51,18 @@ defmodule MobilizonWeb.NodeInfoController do
|
|||||||
localComments: Events.count_local_comments()
|
localComments: Events.count_local_comments()
|
||||||
},
|
},
|
||||||
metadata: %{
|
metadata: %{
|
||||||
nodeName: Keyword.get(@instance, :name)
|
nodeName: CommonConfig.instance_name(),
|
||||||
|
nodeDescription: CommonConfig.instance_description()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response =
|
||||||
|
if version == "2.1" do
|
||||||
|
put_in(response, [:software, :repository], Keyword.get(@instance, :repository))
|
||||||
|
else
|
||||||
|
response
|
||||||
|
end
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_resp_header(
|
|> put_resp_header(
|
||||||
"content-type",
|
"content-type",
|
||||||
|
@ -8,6 +8,15 @@ defmodule MobilizonWeb.NodeInfoControllerTest do
|
|||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response(conn, 200) == %{
|
||||||
"links" => [
|
"links" => [
|
||||||
|
%{
|
||||||
|
"href" =>
|
||||||
|
MobilizonWeb.Router.Helpers.node_info_url(
|
||||||
|
MobilizonWeb.Endpoint,
|
||||||
|
:nodeinfo,
|
||||||
|
"2.0"
|
||||||
|
),
|
||||||
|
"rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0"
|
||||||
|
},
|
||||||
%{
|
%{
|
||||||
"href" =>
|
"href" =>
|
||||||
MobilizonWeb.Router.Helpers.node_info_url(
|
MobilizonWeb.Router.Helpers.node_info_url(
|
||||||
@ -27,10 +36,13 @@ defmodule MobilizonWeb.NodeInfoControllerTest do
|
|||||||
resp = json_response(conn, 200)
|
resp = json_response(conn, 200)
|
||||||
|
|
||||||
assert resp == %{
|
assert resp == %{
|
||||||
"metadata" => %{"nodeName" => Keyword.get(@instance, :name)},
|
"metadata" => %{
|
||||||
|
"nodeName" => Mobilizon.CommonConfig.instance_name(),
|
||||||
|
"nodeDescription" => Mobilizon.CommonConfig.instance_description()
|
||||||
|
},
|
||||||
"openRegistrations" => Keyword.get(@instance, :registrations_open),
|
"openRegistrations" => Keyword.get(@instance, :registrations_open),
|
||||||
"protocols" => ["activitypub"],
|
"protocols" => ["activitypub"],
|
||||||
"services" => %{"inbound" => [], "outbound" => []},
|
"services" => %{"inbound" => [], "outbound" => ["atom1.0"]},
|
||||||
"software" => %{
|
"software" => %{
|
||||||
"name" => "mobilizon",
|
"name" => "mobilizon",
|
||||||
"version" => Keyword.get(@instance, :version),
|
"version" => Keyword.get(@instance, :version),
|
||||||
|
Loading…
Reference in New Issue
Block a user