commit 8f34c2e
default
·
2024-01-23 15:21:48 +0000 UTC
parent f5031ed
mastoapi: added /v1/statuses put support (note edit).
1 files changed,
+46,
-2
+46,
-2
1@@ -2534,8 +2534,6 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
2 if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/"))
3 return 0;
4
5- srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path));
6-
7 int status = 404;
8 xs *args = NULL;
9 char *i_ctype = xs_dict_get(req, "content-type");
10@@ -2583,11 +2581,57 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
11 else
12 status = 401;
13 }
14+ else
15+ if (xs_startswith(cmd, "/v1/statuses")) {
16+ if (logged_in) {
17+ xs *l = xs_split(cmd, "/");
18+ const char *mid = xs_list_get(l, 3);
19+
20+ if (!xs_is_null(mid)) {
21+ const char *md5 = MID_TO_MD5(mid);
22+ xs *rsp = NULL;
23+ xs *msg = NULL;
24+
25+ if (valid_status(timeline_get_by_md5(&snac, md5, &msg))) {
26+ const char *content = xs_dict_get(args, "status");
27+ xs *atls = xs_list_new();
28+ const char *f_content = not_really_markdown(content, &atls);
29+
30+ /* replace fields with new content */
31+ msg = xs_dict_set(msg, "sourceContent", content);
32+ msg = xs_dict_set(msg, "content", f_content);
33+
34+ xs *updated = xs_str_utctime(0, ISO_DATE_SPEC);
35+ msg = xs_dict_set(msg, "updated", updated);
36+
37+ /* overwrite object, not updating the indexes */
38+ object_add_ow(xs_dict_get(msg, "id"), msg);
39+
40+ /* update message */
41+ xs *c_msg = msg_update(&snac, msg);
42+
43+ enqueue_message(&snac, c_msg);
44+
45+ rsp = mastoapi_status(&snac, msg);
46+ }
47+
48+ if (rsp != NULL) {
49+ *body = xs_json_dumps(rsp, 4);
50+ *ctype = "application/json";
51+ status = 200;
52+ }
53+ }
54+ }
55+ else
56+ status = 401;
57+ }
58
59 /* user cleanup */
60 if (logged_in)
61 user_free(&snac);
62
63+ srv_debug(1, xs_fmt("mastoapi_put_handler %s %d", q_path, status));
64+
65 return status;
66 }
67