diff --git a/Cargo.toml b/Cargo.toml index 5ad01efe..96d04275 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ authors = ["Plume contributors"] name = "plume" version = "0.2.0" +repository = "https://github.com/Plume-org/Plume" [dependencies] activitypub = "0.1.3" diff --git a/src/routes/instance.rs b/src/routes/instance.rs index 6a4f9865..37149478 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -216,20 +216,25 @@ pub fn shared_inbox(conn: DbConn, data: SignedJson, headers: }) } -#[get("/nodeinfo")] -pub fn nodeinfo(conn: DbConn) -> Result, ErrorPage> { - Ok(Json(json!({ - "version": "2.0", +#[get("/nodeinfo/")] +pub fn nodeinfo(conn: DbConn, version: String) -> Result, ErrorPage> { + if version != "2.0" || version != "2.1" { + return Err(ErrorPage::from(Error::NotFound)); + } + + let local_inst = Instance::get_local(&*conn)?; + let mut doc = json!({ + "version": version, "software": { - "name": "Plume", - "version": env!("CARGO_PKG_VERSION") + "name": env!("CARGO_PKG_NAME"), + "version": env!("CARGO_PKG_VERSION"), }, "protocols": ["activitypub"], "services": { "inbound": [], "outbound": [] }, - "openRegistrations": true, + "openRegistrations": local_inst.open_registrations, "usage": { "users": { "total": User::count_local(&*conn)? @@ -237,8 +242,17 @@ pub fn nodeinfo(conn: DbConn) -> Result, ErrorPage> { "localPosts": Post::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")] diff --git a/src/routes/well_known.rs b/src/routes/well_known.rs index 3f41c909..332032a2 100644 --- a/src/routes/well_known.rs +++ b/src/routes/well_known.rs @@ -11,7 +11,11 @@ pub fn nodeinfo() -> Content { "links": [ { "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())