diff options
| author | 2023-10-28 07:10:21 +0200 | |
|---|---|---|
| committer | 2023-10-28 07:10:21 +0200 | |
| commit | 5e8eb5f17188809a4340aed8f0382bd44820c96c (patch) | |
| tree | 788c5faf85045c333538dd16618821bd140c81c1 | |
| parent | Updated documentation. (diff) | |
| download | snac2-5e8eb5f17188809a4340aed8f0382bd44820c96c.tar.gz snac2-5e8eb5f17188809a4340aed8f0382bd44820c96c.tar.xz snac2-5e8eb5f17188809a4340aed8f0382bd44820c96c.zip | |
mastoapi: implemented /api/v1/accounts/lookup.
| -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, | |||
| 1049 | if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) | 1049 | if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) |
| 1050 | return 0; | 1050 | return 0; |
| 1051 | 1051 | ||
| 1052 | srv_debug(1, xs_fmt("mastoapi_get_handler %s", q_path)); | ||
| 1053 | |||
| 1054 | int status = 404; | 1052 | int status = 404; |
| 1055 | xs_dict *args = xs_dict_get(req, "q_vars"); | 1053 | xs_dict *args = xs_dict_get(req, "q_vars"); |
| 1056 | xs *cmd = xs_replace_n(q_path, "/api", "", 1); | 1054 | 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, | |||
| 1143 | status = 422; | 1141 | status = 422; |
| 1144 | } | 1142 | } |
| 1145 | else | 1143 | else |
| 1144 | if (strcmp(cmd, "/v1/accounts/lookup") == 0) { /** **/ | ||
| 1145 | /* lookup an account */ | ||
| 1146 | char *acct = xs_dict_get(args, "acct"); | ||
| 1147 | |||
| 1148 | if (!xs_is_null(acct)) { | ||
| 1149 | xs *s = xs_strip_chars_i(xs_dup(acct), "@"); | ||
| 1150 | xs *l = xs_split_n(s, "@", 1); | ||
| 1151 | char *uid = xs_list_get(l, 0); | ||
| 1152 | char *host = xs_list_get(l, 1); | ||
| 1153 | |||
| 1154 | if (uid && (!host || strcmp(host, xs_dict_get(srv_config, "host")) == 0)) { | ||
| 1155 | snac user; | ||
| 1156 | |||
| 1157 | if (user_open(&user, uid)) { | ||
| 1158 | xs *actor = msg_actor(&user); | ||
| 1159 | xs *macct = mastoapi_account(actor); | ||
| 1160 | |||
| 1161 | *body = xs_json_dumps(macct, 4); | ||
| 1162 | *ctype = "application/json"; | ||
| 1163 | status = 200; | ||
| 1164 | |||
| 1165 | user_free(&user); | ||
| 1166 | } | ||
| 1167 | } | ||
| 1168 | } | ||
| 1169 | } | ||
| 1170 | else | ||
| 1146 | if (xs_startswith(cmd, "/v1/accounts/")) { /** **/ | 1171 | if (xs_startswith(cmd, "/v1/accounts/")) { /** **/ |
| 1147 | /* account-related information */ | 1172 | /* account-related information */ |
| 1148 | xs *l = xs_split(cmd, "/"); | 1173 | xs *l = xs_split(cmd, "/"); |
| @@ -1883,6 +1908,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1883 | if (logged_in) | 1908 | if (logged_in) |
| 1884 | user_free(&snac1); | 1909 | user_free(&snac1); |
| 1885 | 1910 | ||
| 1911 | srv_debug(1, xs_fmt("mastoapi_get_handler %s %d", q_path, status)); | ||
| 1912 | |||
| 1886 | return status; | 1913 | return status; |
| 1887 | } | 1914 | } |
| 1888 | 1915 | ||