Update NodeInfo support to 2.1 (#79)

This commit is contained in:
Julien Lavergne 2019-05-24 09:18:19 +02:00 committed by Thomas Citharel
parent 77d766c143
commit a2c181f7fe
3 changed files with 19 additions and 13 deletions

View File

@ -13,7 +13,8 @@ config :mobilizon, :instance,
name: System.get_env("MOBILIZON_INSTANCE_NAME") || "Localhost",
description: System.get_env("MOBILIZON_INSTANCE_DESCRIPTION") || "This is a Mobilizon instance",
version: "1.0.0-dev",
registrations_open: System.get_env("MOBILIZON_INSTANCE_REGISTRATIONS_OPEN") || false
registrations_open: System.get_env("MOBILIZON_INSTANCE_REGISTRATIONS_OPEN") || false,
repository: Mix.Project.config()[:source_url]
config :mime, :types, %{
"application/activity+json" => ["activity-json"],

View File

@ -14,8 +14,8 @@ defmodule MobilizonWeb.NodeInfoController do
response = %{
links: [
%{
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
href: MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, "2.0")
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
href: MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, "2.1")
}
]
}
@ -23,13 +23,14 @@ defmodule MobilizonWeb.NodeInfoController do
json(conn, response)
end
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
def nodeinfo(conn, %{"version" => "2.0"}) do
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
def nodeinfo(conn, %{"version" => "2.1"}) do
response = %{
version: "2.0",
version: "2.1",
software: %{
name: "mobilizon",
version: Keyword.get(@instance, :version)
version: Keyword.get(@instance, :version),
repository: Keyword.get(@instance, :repository)
},
protocols: ["activitypub"],
services: %{
@ -52,7 +53,7 @@ defmodule MobilizonWeb.NodeInfoController do
conn
|> put_resp_header(
"content-type",
"application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
"application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8"
)
|> json(response)
end

View File

@ -13,16 +13,16 @@ defmodule MobilizonWeb.NodeInfoControllerTest do
MobilizonWeb.Router.Helpers.node_info_url(
MobilizonWeb.Endpoint,
:nodeinfo,
"2.0"
"2.1"
),
"rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0"
"rel" => "http://nodeinfo.diaspora.software/ns/schema/2.1"
}
]
}
end
test "Get node info", %{conn: conn} do
conn = get(conn, node_info_path(conn, :nodeinfo, "2.0"))
conn = get(conn, node_info_path(conn, :nodeinfo, "2.1"))
resp = json_response(conn, 200)
@ -31,9 +31,13 @@ defmodule MobilizonWeb.NodeInfoControllerTest do
"openRegistrations" => Keyword.get(@instance, :registrations_open),
"protocols" => ["activitypub"],
"services" => %{"inbound" => [], "outbound" => []},
"software" => %{"name" => "mobilizon", "version" => Keyword.get(@instance, :version)},
"software" => %{
"name" => "mobilizon",
"version" => Keyword.get(@instance, :version),
"repository" => Keyword.get(@instance, :repository)
},
"usage" => %{"localComments" => 0, "localPosts" => 0, "users" => %{"total" => 0}},
"version" => "2.0"
"version" => "2.1"
}
end