commit a4051f7
default
·
2023-04-11 09:00:06 +0000 UTC
parent 79224ca
Started work in /api/v1/statuses.
1 files changed,
+44,
-2
+44,
-2
1@@ -603,10 +603,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 return 0;
3
4 srv_debug(0, xs_fmt("mastoapi_get_handler %s", q_path));
5- {
6+/* {
7 xs *j = xs_json_dumps_pp(req, 4);
8 printf("mastoapi get:\n%s\n", j);
9- }
10+ }*/
11
12 int status = 404;
13 xs_dict *args = xs_dict_get(req, "q_vars");
14@@ -772,6 +772,48 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
15 *ctype = "application/json";
16 status = 200;
17 }
18+ else
19+ if (xs_startswith(cmd, "/statuses/")) {
20+ /* operations on a status */
21+ xs *l = xs_split(cmd, "/");
22+ const char *id = xs_list_get(l, 2);
23+ const char *op = xs_list_get(l, 3);
24+
25+ if (!xs_is_null(id)) {
26+ xs *msg = NULL;
27+ xs *out = NULL;
28+
29+ /* skip the fake part of the id (the date) */
30+ id += 14;
31+
32+ if (valid_status(timeline_get_by_md5(&snac, id, &msg))) {
33+ if (op == NULL) {
34+ /* return the status itself */
35+ }
36+ else
37+ if (strcmp(op, "context") == 0) {
38+ /* return ancestors and children */
39+ srv_debug(0, xs_fmt("mastoapi status: context requested for %s", id));
40+ }
41+ else
42+ if (strcmp(op, "reblogged_by") == 0) {
43+ /* return the list of boosts */
44+ }
45+ else
46+ if (strcmp(op, "favourited_by") == 0) {
47+ /* return the list of likes */
48+ }
49+ }
50+ else
51+ srv_debug(0, xs_fmt("mastoapi status: bad id %s", id));
52+
53+ if (out != NULL) {
54+ *body = xs_json_dumps_pp(out, 4);
55+ *ctype = "application/json";
56+ status = 200;
57+ }
58+ }
59+ }
60
61 /* user cleanup */
62 if (logged_in)