commit 1d00c4e

default  ·  2023-08-21 20:49:46 +0000 UTC
parent 3495c69
The nodeinfo file returns more useful information.
1 files changed,  +28, -4
+28, -4
 1@@ -39,11 +39,35 @@ const char *nodeinfo_2_0_template = ""
 2 xs_str *nodeinfo_2_0(void)
 3 /* builds a nodeinfo json object */
 4 {
 5-    xs *users   = user_list();
 6-    int n_users = xs_list_len(users);
 7-    int n_posts = 0; /* to be implemented someday */
 8+    int n_utotal = 0;
 9+    int n_umonth = 0;
10+    int n_uhyear = 0;
11+    int n_posts  = 0;
12+    xs *users = user_list();
13+    xs_list *p;
14+    char *v;
15+
16+    p = users;
17+    while (xs_list_iter(&p, &v)) {
18+        /* build the full path name to the last usage log */
19+        xs *llfn = xs_fmt("%s/user/%s/lastlog.txt", srv_basedir, v);
20+        double llsecs = (double)time(NULL) - mtime(llfn);
21+
22+        if (llsecs < 60 * 60 * 24 * 30 * 6) {
23+            n_uhyear++;
24+
25+            if (llsecs < 60 * 60 * 24 * 30)
26+                n_umonth++;
27+        }
28+
29+        n_utotal++;
30+
31+        /* build the file to each user public.idx */
32+        xs *pidxfn = xs_fmt("%s/user/%s/private.idx", srv_basedir, v);
33+        n_posts += index_len(pidxfn);
34+    }
35 
36-    return xs_fmt(nodeinfo_2_0_template, n_users, n_users, n_users, n_posts);
37+    return xs_fmt(nodeinfo_2_0_template, n_utotal, n_umonth, n_uhyear, n_posts);
38 }
39 
40