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", name: System.get_env("MOBILIZON_INSTANCE_NAME") || "Localhost",
description: System.get_env("MOBILIZON_INSTANCE_DESCRIPTION") || "This is a Mobilizon instance", description: System.get_env("MOBILIZON_INSTANCE_DESCRIPTION") || "This is a Mobilizon instance",
version: "1.0.0-dev", 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, %{ config :mime, :types, %{
"application/activity+json" => ["activity-json"], "application/activity+json" => ["activity-json"],

View File

@ -14,8 +14,8 @@ defmodule MobilizonWeb.NodeInfoController do
response = %{ response = %{
links: [ links: [
%{ %{
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
href: MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, "2.0") href: MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, "2.1")
} }
] ]
} }
@ -23,13 +23,14 @@ defmodule MobilizonWeb.NodeInfoController do
json(conn, response) json(conn, response)
end end
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
def nodeinfo(conn, %{"version" => "2.0"}) do def nodeinfo(conn, %{"version" => "2.1"}) do
response = %{ response = %{
version: "2.0", version: "2.1",
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: %{
@ -52,7 +53,7 @@ defmodule MobilizonWeb.NodeInfoController do
conn conn
|> put_resp_header( |> put_resp_header(
"content-type", "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) |> json(response)
end end

View File

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