diff options
| author | 2024-01-23 16:21:48 +0100 | |
|---|---|---|
| committer | 2024-01-23 16:21:48 +0100 | |
| commit | 8f34c2e740f169d5f5202af9086222cdd56c7993 (patch) | |
| tree | 9debbe2d53288331162f5c895d3feaeca8f662a0 | |
| parent | mastoapi: added support for status/.../source. (diff) | |
| download | snac2-8f34c2e740f169d5f5202af9086222cdd56c7993.tar.gz snac2-8f34c2e740f169d5f5202af9086222cdd56c7993.tar.xz snac2-8f34c2e740f169d5f5202af9086222cdd56c7993.zip | |
mastoapi: added /v1/statuses put support (note edit).
| -rw-r--r-- | mastoapi.c | 48 |
1 files changed, 46 insertions, 2 deletions
| @@ -2534,8 +2534,6 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, | |||
| 2534 | if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) | 2534 | if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) |
| 2535 | return 0; | 2535 | return 0; |
| 2536 | 2536 | ||
| 2537 | srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path)); | ||
| 2538 | |||
| 2539 | int status = 404; | 2537 | int status = 404; |
| 2540 | xs *args = NULL; | 2538 | xs *args = NULL; |
| 2541 | char *i_ctype = xs_dict_get(req, "content-type"); | 2539 | char *i_ctype = xs_dict_get(req, "content-type"); |
| @@ -2583,11 +2581,57 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, | |||
| 2583 | else | 2581 | else |
| 2584 | status = 401; | 2582 | status = 401; |
| 2585 | } | 2583 | } |
| 2584 | else | ||
| 2585 | if (xs_startswith(cmd, "/v1/statuses")) { | ||
| 2586 | if (logged_in) { | ||
| 2587 | xs *l = xs_split(cmd, "/"); | ||
| 2588 | const char *mid = xs_list_get(l, 3); | ||
| 2589 | |||
| 2590 | if (!xs_is_null(mid)) { | ||
| 2591 | const char *md5 = MID_TO_MD5(mid); | ||
| 2592 | xs *rsp = NULL; | ||
| 2593 | xs *msg = NULL; | ||
| 2594 | |||
| 2595 | if (valid_status(timeline_get_by_md5(&snac, md5, &msg))) { | ||
| 2596 | const char *content = xs_dict_get(args, "status"); | ||
| 2597 | xs *atls = xs_list_new(); | ||
| 2598 | const char *f_content = not_really_markdown(content, &atls); | ||
| 2599 | |||
| 2600 | /* replace fields with new content */ | ||
| 2601 | msg = xs_dict_set(msg, "sourceContent", content); | ||
| 2602 | msg = xs_dict_set(msg, "content", f_content); | ||
| 2603 | |||
| 2604 | xs *updated = xs_str_utctime(0, ISO_DATE_SPEC); | ||
| 2605 | msg = xs_dict_set(msg, "updated", updated); | ||
| 2606 | |||
| 2607 | /* overwrite object, not updating the indexes */ | ||
| 2608 | object_add_ow(xs_dict_get(msg, "id"), msg); | ||
| 2609 | |||
| 2610 | /* update message */ | ||
| 2611 | xs *c_msg = msg_update(&snac, msg); | ||
| 2612 | |||
| 2613 | enqueue_message(&snac, c_msg); | ||
| 2614 | |||
| 2615 | rsp = mastoapi_status(&snac, msg); | ||
| 2616 | } | ||
| 2617 | |||
| 2618 | if (rsp != NULL) { | ||
| 2619 | *body = xs_json_dumps(rsp, 4); | ||
| 2620 | *ctype = "application/json"; | ||
| 2621 | status = 200; | ||
| 2622 | } | ||
| 2623 | } | ||
| 2624 | } | ||
| 2625 | else | ||
| 2626 | status = 401; | ||
| 2627 | } | ||
| 2586 | 2628 | ||
| 2587 | /* user cleanup */ | 2629 | /* user cleanup */ |
| 2588 | if (logged_in) | 2630 | if (logged_in) |
| 2589 | user_free(&snac); | 2631 | user_free(&snac); |
| 2590 | 2632 | ||
| 2633 | srv_debug(1, xs_fmt("mastoapi_put_handler %s %d", q_path, status)); | ||
| 2634 | |||
| 2591 | return status; | 2635 | return status; |
| 2592 | } | 2636 | } |
| 2593 | 2637 | ||