From 49134582055a174951b23314170ec42c33796325 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 17 Mar 2025 08:18:41 +0100 Subject: mastoapi: added support for /api/v1/custom_emojis (contributed by violette). --- mastoapi.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 1927b0a..3b96ca1 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2116,8 +2116,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } else if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/ - /* are you kidding me? */ - *body = xs_dup("[]"); + xs *emo = emojis(); + xs *list = xs_list_new(); + int c = 0; + const xs_str *k; + const xs_val *v; + while(xs_dict_next(emo, &k, &v, &c)) { + xs *current = xs_dict_new(); + if (xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) { + /* remove first and last colon */ + char *shortcode = (char *)k; + shortcode[strlen(k) - 1] = '\0'; + current = xs_dict_append(current, "shortcode", shortcode + 1); + current = xs_dict_append(current, "url", v); + current = xs_dict_append(current, "static_url", v); + current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE)); + list = xs_list_append(list, current); + } + } + *body = xs_json_dumps(list, 0); *ctype = "application/json"; status = HTTP_STATUS_OK; } -- cgit v1.2.3 From b5f0b4ba2d45165cc2a70ac5d35d545cb039749d Mon Sep 17 00:00:00 2001 From: default Date: Mon, 17 Mar 2025 08:24:37 +0100 Subject: Minor tweak. --- mastoapi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 3b96ca1..8d61681 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2125,9 +2125,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *current = xs_dict_new(); if (xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) { /* remove first and last colon */ - char *shortcode = (char *)k; - shortcode[strlen(k) - 1] = '\0'; - current = xs_dict_append(current, "shortcode", shortcode + 1); + xs *shortcode = xs_replace(k, ":", ""); + current = xs_dict_append(current, "shortcode", shortcode); current = xs_dict_append(current, "url", v); current = xs_dict_append(current, "static_url", v); current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE)); -- cgit v1.2.3