Update nodeinfo (#446)

Fix #433

I added the repo link to Cargo.toml so that `software.repository` could be configurable like @rhaamo suggested. I don't know if it's ok to include `software.repository` without bumping the schema version, but I didn't know if that would break any clients that parse nodeinfo with a hardcoded schema version.
This commit is contained in:
zcdunn 2019-02-17 07:42:59 -05:00 committed by Baptiste Gelez
parent 64d1944715
commit 7bac70a483
3 changed files with 29 additions and 10 deletions

View File

@ -2,6 +2,7 @@
authors = ["Plume contributors"] authors = ["Plume contributors"]
name = "plume" name = "plume"
version = "0.2.0" version = "0.2.0"
repository = "https://github.com/Plume-org/Plume"
[dependencies] [dependencies]
activitypub = "0.1.3" activitypub = "0.1.3"

View File

@ -216,20 +216,25 @@ pub fn shared_inbox(conn: DbConn, data: SignedJson<serde_json::Value>, headers:
}) })
} }
#[get("/nodeinfo")] #[get("/nodeinfo/<version>")]
pub fn nodeinfo(conn: DbConn) -> Result<Json<serde_json::Value>, ErrorPage> { pub fn nodeinfo(conn: DbConn, version: String) -> Result<Json<serde_json::Value>, ErrorPage> {
Ok(Json(json!({ if version != "2.0" || version != "2.1" {
"version": "2.0", return Err(ErrorPage::from(Error::NotFound));
}
let local_inst = Instance::get_local(&*conn)?;
let mut doc = json!({
"version": version,
"software": { "software": {
"name": "Plume", "name": env!("CARGO_PKG_NAME"),
"version": env!("CARGO_PKG_VERSION") "version": env!("CARGO_PKG_VERSION"),
}, },
"protocols": ["activitypub"], "protocols": ["activitypub"],
"services": { "services": {
"inbound": [], "inbound": [],
"outbound": [] "outbound": []
}, },
"openRegistrations": true, "openRegistrations": local_inst.open_registrations,
"usage": { "usage": {
"users": { "users": {
"total": User::count_local(&*conn)? "total": User::count_local(&*conn)?
@ -237,8 +242,17 @@ pub fn nodeinfo(conn: DbConn) -> Result<Json<serde_json::Value>, ErrorPage> {
"localPosts": Post::count_local(&*conn)?, "localPosts": Post::count_local(&*conn)?,
"localComments": Comment::count_local(&*conn)? "localComments": Comment::count_local(&*conn)?
}, },
"metadata": {} "metadata": {
}))) "nodeName": local_inst.name,
"nodeDescription": local_inst.short_description
}
});
if version == "2.1" {
doc["software"]["repository"] = json!(env!("CARGO_PKG_REPOSITORY"));
}
Ok(Json(doc))
} }
#[get("/about")] #[get("/about")]

View File

@ -11,7 +11,11 @@ pub fn nodeinfo() -> Content<String> {
"links": [ "links": [
{ {
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0", "rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
"href": ap_url(&format!("{domain}/nodeinfo", domain = BASE_URL.as_str())) "href": ap_url(&format!("{domain}/nodeinfo/2.0", domain = BASE_URL.as_str()))
},
{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1",
"href": ap_url(&format!("{domain}/nodeinfo/2.1", domain = BASE_URL.as_str()))
} }
] ]
}).to_string()) }).to_string())