commit 512058b

default  ·  2023-04-15 16:06:18 +0000 UTC
parent 95d90e5
Added entrypoint /push/subscription.

The returned object is just wild guessing, I don't understand all
this things. Anyway, the offical app keeps crashing.
1 files changed,  +40, -4
+40, -4
 1@@ -1009,17 +1009,24 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2         ins = xs_dict_append(ins, "source_url",  "https:/" "/comam.es/what-is-snac");
 3         ins = xs_dict_append(ins, "description", host);
 4 
 5+        ins = xs_dict_append(ins, "short_description", host);
 6+
 7         xs *susie = xs_fmt("%s/susie.png", srv_baseurl);
 8         ins = xs_dict_append(ins, "thumbnail", susie);
 9 
10-        xs *d2 = xs_dict_new();
11-        d2 = xs_dict_append(d2, "email", "admin@localhost");
12-        ins = xs_dict_append(ins, "contact", d2);
13+        ins = xs_dict_append(ins, "email", "admin@localhost");
14 
15         xs *l1 = xs_list_new();
16         ins = xs_dict_append(ins, "rules",     l1);
17+
18+        l1 = xs_list_append(l1, "en");
19         ins = xs_dict_append(ins, "languages", l1);
20 
21+        xs *d1 = xs_dict_new();
22+        ins = xs_dict_append(ins, "urls",            d1);
23+        ins = xs_dict_append(ins, "stats",           d1);
24+        ins = xs_dict_append(ins, "configuration",   d1);
25+
26         *body  = xs_json_dumps_pp(ins, 4);
27         *ctype = "application/json";
28         status = 200;
29@@ -1164,7 +1171,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
30 /*    {
31         xs *j = xs_json_dumps_pp(req, 4);
32         printf("mastoapi post:\n%s\n", j);
33-   }*/
34+    }*/
35 
36     int status    = 404;
37     xs *args      = NULL;
38@@ -1333,6 +1340,35 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
39         else
40             status = 401;
41     }
42+    else
43+    if (strcmp(cmd, "/push/subscription") == 0) {
44+        /* I don't know what I'm doing */
45+        if (logged_in) {
46+            char *v;
47+
48+            xs *wpush = xs_dict_new();
49+
50+            wpush = xs_dict_append(wpush, "id", "1");
51+
52+            v = xs_dict_get(args, "data");
53+            v = xs_dict_get(v, "alerts");
54+            wpush = xs_dict_append(wpush, "alerts", v);
55+
56+            v = xs_dict_get(args, "subscription");
57+            v = xs_dict_get(v, "endpoint");
58+            wpush = xs_dict_append(wpush, "endpoint", v);
59+
60+            xs *server_key = random_str();
61+            wpush = xs_dict_append(wpush, "server_key", server_key);
62+
63+            *body  = xs_json_dumps_pp(wpush, 4);
64+            *ctype = "application/json";
65+            status = 200;
66+        }
67+        else
68+            status = 401;
69+
70+    }
71 
72     /* user cleanup */
73     if (logged_in)