diff options
| author | 2025-03-17 08:18:41 +0100 | |
|---|---|---|
| committer | 2025-03-17 08:18:41 +0100 | |
| commit | 49134582055a174951b23314170ec42c33796325 (patch) | |
| tree | 72337c4455df8d856d516c33797e87038df28fde | |
| parent | Merge pull request 'Translation for pt_BR.po new strings 🇧🇷🇵🇹' (#... (diff) | |
| download | snac2-49134582055a174951b23314170ec42c33796325.tar.gz snac2-49134582055a174951b23314170ec42c33796325.tar.xz snac2-49134582055a174951b23314170ec42c33796325.zip | |
mastoapi: added support for /api/v1/custom_emojis (contributed by violette).
| -rw-r--r-- | format.c | 1 | ||||
| -rw-r--r-- | html.c | 1 | ||||
| -rw-r--r-- | mastoapi.c | 21 |
3 files changed, 21 insertions, 2 deletions
| @@ -94,6 +94,7 @@ static xs_str *format_line(const char *line, xs_list **attach) | |||
| 94 | "`[^`]+`" "|" | 94 | "`[^`]+`" "|" |
| 95 | "~~[^~]+~~" "|" | 95 | "~~[^~]+~~" "|" |
| 96 | "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" | 96 | "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|" |
| 97 | ":.+:" "|" //emotes | ||
| 97 | "_[^_]+_" "|" //anzu | 98 | "_[^_]+_" "|" //anzu |
| 98 | "__[^_]+__" "|" //anzu | 99 | "__[^_]+__" "|" //anzu |
| 99 | "!\\[[^]]+\\]\\([^\\)]+\\)" "|" | 100 | "!\\[[^]]+\\]\\([^\\)]+\\)" "|" |
| @@ -92,6 +92,7 @@ xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems, const char *p | |||
| 92 | xs_html *img = xs_html_sctag("img", | 92 | xs_html *img = xs_html_sctag("img", |
| 93 | xs_html_attr("loading", "lazy"), | 93 | xs_html_attr("loading", "lazy"), |
| 94 | xs_html_attr("src", url), | 94 | xs_html_attr("src", url), |
| 95 | xs_html_attr("alt", n), | ||
| 95 | xs_html_attr("style", style)); | 96 | xs_html_attr("style", style)); |
| 96 | 97 | ||
| 97 | xs *s1 = xs_html_render(img); | 98 | xs *s1 = xs_html_render(img); |
| @@ -2116,8 +2116,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2116 | } | 2116 | } |
| 2117 | else | 2117 | else |
| 2118 | if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/ | 2118 | if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/ |
| 2119 | /* are you kidding me? */ | 2119 | xs *emo = emojis(); |
| 2120 | *body = xs_dup("[]"); | 2120 | xs *list = xs_list_new(); |
| 2121 | int c = 0; | ||
| 2122 | const xs_str *k; | ||
| 2123 | const xs_val *v; | ||
| 2124 | while(xs_dict_next(emo, &k, &v, &c)) { | ||
| 2125 | xs *current = xs_dict_new(); | ||
| 2126 | if (xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) { | ||
| 2127 | /* remove first and last colon */ | ||
| 2128 | char *shortcode = (char *)k; | ||
| 2129 | shortcode[strlen(k) - 1] = '\0'; | ||
| 2130 | current = xs_dict_append(current, "shortcode", shortcode + 1); | ||
| 2131 | current = xs_dict_append(current, "url", v); | ||
| 2132 | current = xs_dict_append(current, "static_url", v); | ||
| 2133 | current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE)); | ||
| 2134 | list = xs_list_append(list, current); | ||
| 2135 | } | ||
| 2136 | } | ||
| 2137 | *body = xs_json_dumps(list, 0); | ||
| 2121 | *ctype = "application/json"; | 2138 | *ctype = "application/json"; |
| 2122 | status = HTTP_STATUS_OK; | 2139 | status = HTTP_STATUS_OK; |
| 2123 | } | 2140 | } |