Browse Source

Publish contact email address on nodeinfo and Mastodon-API statistics

pull/78/head
Toromino 3 months ago
parent
commit
cb52f7e7d8
3 changed files with 29 additions and 13 deletions
  1. 1
    0
      env.toml.sample
  2. 15
    5
      src/mastodon_api/mod.rs
  3. 13
    8
      src/well_known/nodeinfo.rs

+ 1
- 0
env.toml.sample View File

@@ -20,4 +20,5 @@ port = 8000
20 20
 [node]
21 21
 name = "Kibou"
22 22
 description = "A Kibou instance"
23
+contact_email = "kibou@example.tld"
23 24
 registrations_enabled = true

+ 15
- 5
src/mastodon_api/mod.rs View File

@@ -1,6 +1,9 @@
1 1
 pub mod controller;
2 2
 pub mod routes;
3 3
 
4
+use activity;
5
+use actor;
6
+use database;
4 7
 use env;
5 8
 use rocket::request;
6 9
 use rocket::request::FromRequest;
@@ -9,6 +12,7 @@ use rocket::Outcome;
9 12
 use rocket_contrib::json;
10 13
 use rocket_contrib::json::JsonValue;
11 14
 use serde::{Deserialize, Serialize};
15
+use serde_json;
12 16
 
13 17
 #[derive(Serialize, Deserialize)]
14 18
 pub struct Account {
@@ -86,8 +90,8 @@ pub struct Instance {
86 90
     pub email: String,
87 91
     pub version: String,
88 92
     pub thumbnail: Option<String>,
89
-    pub urls: String,
90
-    pub stats: String,
93
+    pub urls: serde_json::Value,
94
+    pub stats: serde_json::Value,
91 95
     pub languages: Vec<String>,
92 96
     pub contact_account: Option<Account>,
93 97
 }
@@ -212,6 +216,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for AuthorizationHeader {
212 216
 }
213 217
 
214 218
 pub fn get_instance_info() -> JsonValue {
219
+    let database = database::establish_connection();
215 220
     json!(Instance {
216 221
         uri: format!(
217 222
             "{base_scheme}://{base_domain}",
@@ -220,11 +225,16 @@ pub fn get_instance_info() -> JsonValue {
220 225
         ),
221 226
         title: env::get_value(String::from("node.name")),
222 227
         description: env::get_value(String::from("node.description")),
223
-        email: String::from(""),
228
+        email: env::get_value(String::from("node.contact_email")),
224 229
         version: String::from("2.3.0 (compatible; Kibou 0.1)"),
225 230
         thumbnail: None,
226
-        urls: String::from(""),
227
-        stats: String::from(""),
231
+        // Kibou does not support Streaming_API yet, but this value is not nullable according to
232
+        // Mastodon-API's specifications, so that is why it is showing an empty value instead
233
+        urls: serde_json::json!({"streaming_api": ""}),
234
+        // `domain_count` always stays 0 as Kibou does not keep data about remote nodes
235
+        stats: serde_json::json!({"user_count": actor::count_local_actors(&database).unwrap_or_else(|_| 0),
236
+        "status_count": activity::count_local_ap_notes(&database).unwrap_or_else(|_| 0),
237
+        "domain_count": 0}),
228 238
         languages: vec![],
229 239
         contact_account: None
230 240
     })

+ 13
- 8
src/well_known/nodeinfo.rs View File

@@ -36,10 +36,12 @@ pub fn nodeinfo_v2() -> JsonValue {
36 36
             "name": env!("CARGO_PKG_NAME")
37 37
         },
38 38
         "protocols": [
39
-        "activitypub"
39
+        "activitypub",
40
+        "litepub"
40 41
         ],
41 42
         "nodeName": env::get_value(String::from("node.name")),
42 43
         "nodeDescription": env::get_value(String::from("node.description")),
44
+        "nodeContactEmail": env::get_value(String::from("node.contact_email")),
43 45
         "services":{
44 46
             "outbound": [
45 47
 
@@ -56,12 +58,12 @@ pub fn nodeinfo_v2() -> JsonValue {
56 58
             "localPosts": get_local_posts()
57 59
         },
58 60
         "metadata": {
59
-
60
-        },
61
-        "features": [
61
+            "features": [
62
+            "kibou_api",
62 63
             "mastodon_api",
63 64
             "webfinger"
64 65
         ]
66
+        }
65 67
     })
66 68
 }
67 69
 
@@ -78,10 +80,12 @@ pub fn nodeinfo_v2_1() -> JsonValue {
78 80
             "repository": "https://git.cybre.club/kibouproject/kibou"
79 81
         },
80 82
         "protocols": [
81
-        "activitypub"
83
+        "activitypub",
84
+        "litepub"
82 85
         ],
83 86
         "nodeName": env::get_value(String::from("node.name")),
84 87
         "nodeDescription": env::get_value(String::from("node.description")),
88
+        "nodeContactEmail": env::get_value(String::from("node.contact_email")),
85 89
         "services":{
86 90
             "outbound": [
87 91
 
@@ -98,12 +102,13 @@ pub fn nodeinfo_v2_1() -> JsonValue {
98 102
             "localPosts": get_local_posts()
99 103
         },
100 104
         "metadata": {
101
-
102
-        },
103
-        "features": [
105
+    "features": [
106
+            "kibou_api",
104 107
             "mastodon_api",
105 108
             "webfinger"
106 109
         ]
110
+
111
+        }
107 112
     })
108 113
 }
109 114
 

Loading…
Cancel
Save