commit d329477
Claire
·
2026-08-28 10:26:48 +0000 UTC
parent 5344aca
mastoapi: implemented /v1/media.
1 files changed,
+37,
-0
+37,
-0
1@@ -3170,6 +3170,43 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 else
3 status = HTTP_STATUS_UNAUTHORIZED;
4 }
5+ else
6+ if (xs_startswith(cmd, "/v1/media/") || xs_startswith(cmd, "/v2/media/")) { /** **/
7+ if (logged_in) {
8+ xs *p = xs_split(cmd, "/");
9+ const char *id = xs_list_get(p, -1);
10+
11+ if (xs_is_string(id)) {
12+ xs *filename = xs_fmt("%s/static/%s", snac1.basedir, id);
13+
14+ if (mtime(filename)) {
15+ /* file exists */
16+ xs *alt = static_get_meta(&snac1, id);
17+ xs *url = xs_fmt("%s/s/%s", snac1.actor, id);
18+ xs *mime = xs_split(xs_mime_by_ext(filename), "/");
19+ const char *type = xs_list_get(mime, 0);
20+
21+ if (!xs_match(type, "image|video|audio"))
22+ type = "unknown";
23+
24+ xs *d = xs_dict_new();
25+
26+ d = xs_dict_set(d, "id", id);
27+ d = xs_dict_set(d, "url", url);
28+ d = xs_dict_set(d, "preview_url", url);
29+ d = xs_dict_set(d, "remote_url", url);
30+ d = xs_dict_set(d, "type", type);
31+ d = xs_dict_set(d, "description", xs_or(alt, ""));
32+
33+ *body = xs_json_dumps(d, 4);
34+ *ctype = "application/json";
35+ status = HTTP_STATUS_OK;
36+ }
37+ }
38+ }
39+ else
40+ status = HTTP_STATUS_UNAUTHORIZED;
41+ }
42
43 /* user cleanup */
44 if (logged_in)