commit 4913458
default
·
2025-03-17 07:18:41 +0000 UTC
parent 4c23d1f
mastoapi: added support for /api/v1/custom_emojis (contributed by violette).
3 files changed,
+21,
-2
M
format.c
+1,
-0
1@@ -94,6 +94,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
2 "`[^`]+`" "|"
3 "~~[^~]+~~" "|"
4 "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|"
5+ ":.+:" "|" //emotes
6 "_[^_]+_" "|" //anzu
7 "__[^_]+__" "|" //anzu
8 "!\\[[^]]+\\]\\([^\\)]+\\)" "|"
M
html.c
+1,
-0
1@@ -92,6 +92,7 @@ xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems, const char *p
2 xs_html *img = xs_html_sctag("img",
3 xs_html_attr("loading", "lazy"),
4 xs_html_attr("src", url),
5+ xs_html_attr("alt", n),
6 xs_html_attr("style", style));
7
8 xs *s1 = xs_html_render(img);
+19,
-2
1@@ -2116,8 +2116,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 }
3 else
4 if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/
5- /* are you kidding me? */
6- *body = xs_dup("[]");
7+ xs *emo = emojis();
8+ xs *list = xs_list_new();
9+ int c = 0;
10+ const xs_str *k;
11+ const xs_val *v;
12+ while(xs_dict_next(emo, &k, &v, &c)) {
13+ xs *current = xs_dict_new();
14+ if (xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) {
15+ /* remove first and last colon */
16+ char *shortcode = (char *)k;
17+ shortcode[strlen(k) - 1] = '\0';
18+ current = xs_dict_append(current, "shortcode", shortcode + 1);
19+ current = xs_dict_append(current, "url", v);
20+ current = xs_dict_append(current, "static_url", v);
21+ current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE));
22+ list = xs_list_append(list, current);
23+ }
24+ }
25+ *body = xs_json_dumps(list, 0);
26 *ctype = "application/json";
27 status = HTTP_STATUS_OK;
28 }