diff options
author | default <nobody@localhost> | 2023-10-28 07:10:21 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-10-28 07:10:21 +0200 |
commit | 5e8eb5f17188809a4340aed8f0382bd44820c96c (patch) | |
tree | 788c5faf85045c333538dd16618821bd140c81c1 /mastoapi.c | |
parent | 71225fc271ddfd140d1c85172247c27e608052e1 (diff) |
mastoapi: implemented /api/v1/accounts/lookup.
Diffstat (limited to 'mastoapi.c')
-rw-r--r-- | mastoapi.c | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -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; } |