mastoapi: implemented /api/v1/accounts/lookup.

This commit is contained in:
default 2023-10-28 07:10:21 +02:00
parent 71225fc271
commit 5e8eb5f171

View File

@ -1049,8 +1049,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/"))
return 0;
srv_debug(1, xs_fmt("mastoapi_get_handler %s", q_path));
int status = 404;
xs_dict *args = xs_dict_get(req, "q_vars");
xs *cmd = xs_replace_n(q_path, "/api", "", 1);
@ -1143,6 +1141,33 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
status = 422;
}
else
if (strcmp(cmd, "/v1/accounts/lookup") == 0) { /** **/
/* lookup an account */
char *acct = xs_dict_get(args, "acct");
if (!xs_is_null(acct)) {
xs *s = xs_strip_chars_i(xs_dup(acct), "@");
xs *l = xs_split_n(s, "@", 1);
char *uid = xs_list_get(l, 0);
char *host = xs_list_get(l, 1);
if (uid && (!host || strcmp(host, xs_dict_get(srv_config, "host")) == 0)) {
snac user;
if (user_open(&user, uid)) {
xs *actor = msg_actor(&user);
xs *macct = mastoapi_account(actor);
*body = xs_json_dumps(macct, 4);
*ctype = "application/json";
status = 200;
user_free(&user);
}
}
}
}
else
if (xs_startswith(cmd, "/v1/accounts/")) { /** **/
/* account-related information */
xs *l = xs_split(cmd, "/");
@ -1883,6 +1908,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
if (logged_in)
user_free(&snac1);
srv_debug(1, xs_fmt("mastoapi_get_handler %s %d", q_path, status));
return status;
}