commit 5e8eb5f
default
·
2023-10-28 05:10:21 +0000 UTC
parent 71225fc
mastoapi: implemented /api/v1/accounts/lookup.
1 files changed,
+29,
-2
+29,
-2
1@@ -1049,8 +1049,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/"))
3 return 0;
4
5- srv_debug(1, xs_fmt("mastoapi_get_handler %s", q_path));
6-
7 int status = 404;
8 xs_dict *args = xs_dict_get(req, "q_vars");
9 xs *cmd = xs_replace_n(q_path, "/api", "", 1);
10@@ -1143,6 +1141,33 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
11 status = 422;
12 }
13 else
14+ if (strcmp(cmd, "/v1/accounts/lookup") == 0) { /** **/
15+ /* lookup an account */
16+ char *acct = xs_dict_get(args, "acct");
17+
18+ if (!xs_is_null(acct)) {
19+ xs *s = xs_strip_chars_i(xs_dup(acct), "@");
20+ xs *l = xs_split_n(s, "@", 1);
21+ char *uid = xs_list_get(l, 0);
22+ char *host = xs_list_get(l, 1);
23+
24+ if (uid && (!host || strcmp(host, xs_dict_get(srv_config, "host")) == 0)) {
25+ snac user;
26+
27+ if (user_open(&user, uid)) {
28+ xs *actor = msg_actor(&user);
29+ xs *macct = mastoapi_account(actor);
30+
31+ *body = xs_json_dumps(macct, 4);
32+ *ctype = "application/json";
33+ status = 200;
34+
35+ user_free(&user);
36+ }
37+ }
38+ }
39+ }
40+ else
41 if (xs_startswith(cmd, "/v1/accounts/")) { /** **/
42 /* account-related information */
43 xs *l = xs_split(cmd, "/");
44@@ -1883,6 +1908,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
45 if (logged_in)
46 user_free(&snac1);
47
48+ srv_debug(1, xs_fmt("mastoapi_get_handler %s %d", q_path, status));
49+
50 return status;
51 }
52