summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar default2024-04-29 08:29:18 +0200
committerGravatar default2024-04-29 08:29:18 +0200
commit9a13e330f12aaf0fc1535e922efbf315308d252b (patch)
treee16476d4490adbbb57072fa0936c92bfdd1134d5 /mastoapi.c
parentStart of list support. (diff)
downloadpenes-snac2-9a13e330f12aaf0fc1535e922efbf315308d252b.tar.gz
penes-snac2-9a13e330f12aaf0fc1535e922efbf315308d252b.tar.xz
penes-snac2-9a13e330f12aaf0fc1535e922efbf315308d252b.zip
More work in lists.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c51
1 files changed, 41 insertions, 10 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 20d6208..54d2777 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1766,7 +1766,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1766 } 1766 }
1767 else 1767 else
1768 if (strcmp(cmd, "/v1/lists") == 0) { /** **/ 1768 if (strcmp(cmd, "/v1/lists") == 0) { /** **/
1769 /* snac does not support lists */
1770 if (logged_in) { 1769 if (logged_in) {
1771 xs *lol = list_maint(&snac1, NULL, 0); 1770 xs *lol = list_maint(&snac1, NULL, 0);
1772 xs *l = xs_list_new(); 1771 xs *l = xs_list_new();
@@ -2656,17 +2655,22 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
2656 2655
2657 if (xs_type(title) == XSTYPE_STRING) { 2656 if (xs_type(title) == XSTYPE_STRING) {
2658 /* add the list */ 2657 /* add the list */
2659 list_maint(&snac, title, 1);
2660
2661 xs *out = xs_dict_new(); 2658 xs *out = xs_dict_new();
2662 2659
2663 out = xs_dict_append(out, "title", title); 2660 if (xs_type(list_maint(&snac, title, 1)) == XSTYPE_TRUE) {
2664 out = xs_dict_append(out, "replies_policy", xs_dict_get_def(args, "replies_policy", "list")); 2661 out = xs_dict_append(out, "title", title);
2665 out = xs_dict_append(out, "exclusive", xs_stock(XSTYPE_FALSE)); 2662 out = xs_dict_append(out, "replies_policy", xs_dict_get_def(args, "replies_policy", "list"));
2663 out = xs_dict_append(out, "exclusive", xs_stock(XSTYPE_FALSE));
2664
2665 status = 200;
2666 }
2667 else {
2668 out = xs_dict_append(out, "error", "cannot create list");
2669 status = 422;
2670 }
2666 2671
2667 *body = xs_json_dumps(out, 4); 2672 *body = xs_json_dumps(out, 4);
2668 *ctype = "application/json"; 2673 *ctype = "application/json";
2669 status = 200;
2670 } 2674 }
2671 else 2675 else
2672 status = 422; 2676 status = 422;
@@ -2691,16 +2695,43 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path,
2691 (void)b_size; 2695 (void)b_size;
2692 (void)ctype; 2696 (void)ctype;
2693 2697
2698 int status = 404;
2699
2694 if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) 2700 if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/"))
2695 return 0; 2701 return 0;
2696 2702
2697 srv_debug(1, xs_fmt("mastoapi_delete_handler %s", q_path)); 2703 snac snac = {0};
2704 int logged_in = process_auth_token(&snac, req);
2705
2698 xs *cmd = xs_replace_n(q_path, "/api", "", 1); 2706 xs *cmd = xs_replace_n(q_path, "/api", "", 1);
2707
2699 if (xs_startswith(cmd, "/v1/push/subscription") || xs_startswith(cmd, "/v2/push/subscription")) { /** **/ 2708 if (xs_startswith(cmd, "/v1/push/subscription") || xs_startswith(cmd, "/v2/push/subscription")) { /** **/
2700 // pretend we deleted it, since it doesn't exist anyway 2709 // pretend we deleted it, since it doesn't exist anyway
2701 return 200; 2710 status = 200;
2702 } 2711 }
2703 return 0; 2712 else
2713 if (xs_startswith(cmd, "/v1/lists/")) {
2714 if (logged_in) {
2715 xs *l = xs_split(cmd, "/");
2716 char *id = xs_list_get(l, -1);
2717
2718 if (xs_is_hex(id)) {
2719 list_maint(&snac, id, 2);
2720 }
2721
2722 status = 200;
2723 }
2724 else
2725 status = 401;
2726 }
2727
2728 /* user cleanup */
2729 if (logged_in)
2730 user_free(&snac);
2731
2732 srv_debug(1, xs_fmt("mastoapi_delete_handler %s %d", q_path, status));
2733
2734 return status;
2704} 2735}
2705 2736
2706 2737