mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Only allow logged-in user to use search API
This commit is contained in:
parent
2b64892e83
commit
15137fc5c7
1 changed files with 31 additions and 27 deletions
58
mastoapi.c
58
mastoapi.c
|
@ -1627,43 +1627,47 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v2/search") == 0) { /** **/
|
if (strcmp(cmd, "/v2/search") == 0) { /** **/
|
||||||
const char *q = xs_dict_get(args, "q");
|
if (logged_in) {
|
||||||
const char *type = xs_dict_get(args, "type");
|
const char *q = xs_dict_get(args, "q");
|
||||||
const char *offset = xs_dict_get(args, "offset");
|
const char *type = xs_dict_get(args, "type");
|
||||||
|
const char *offset = xs_dict_get(args, "offset");
|
||||||
|
|
||||||
xs *acl = xs_list_new();
|
xs *acl = xs_list_new();
|
||||||
xs *stl = xs_list_new();
|
xs *stl = xs_list_new();
|
||||||
xs *htl = xs_list_new();
|
xs *htl = xs_list_new();
|
||||||
xs *res = xs_dict_new();
|
xs *res = xs_dict_new();
|
||||||
|
|
||||||
if (xs_is_null(offset) || strcmp(offset, "0") == 0) {
|
if (xs_is_null(offset) || strcmp(offset, "0") == 0) {
|
||||||
/* reply something only for offset 0; otherwise,
|
/* reply something only for offset 0; otherwise,
|
||||||
apps like Tusky keep asking again and again */
|
apps like Tusky keep asking again and again */
|
||||||
|
|
||||||
if (!xs_is_null(q) && !xs_is_null(type) && strcmp(type, "accounts") == 0) {
|
if (!xs_is_null(q) && !xs_is_null(type) && strcmp(type, "accounts") == 0) {
|
||||||
/* do a webfinger query */
|
/* do a webfinger query */
|
||||||
char *actor = NULL;
|
char *actor = NULL;
|
||||||
char *user = NULL;
|
char *user = NULL;
|
||||||
|
|
||||||
if (valid_status(webfinger_request(q, &actor, &user))) {
|
if (valid_status(webfinger_request(q, &actor, &user))) {
|
||||||
xs *actor_o = NULL;
|
xs *actor_o = NULL;
|
||||||
|
|
||||||
if (valid_status(actor_request(&snac1, actor, &actor_o))) {
|
if (valid_status(actor_request(&snac1, actor, &actor_o))) {
|
||||||
xs *acct = mastoapi_account(actor_o);
|
xs *acct = mastoapi_account(actor_o);
|
||||||
|
|
||||||
acl = xs_list_append(acl, acct);
|
acl = xs_list_append(acl, acct);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = xs_dict_append(res, "accounts", acl);
|
||||||
|
res = xs_dict_append(res, "statuses", stl);
|
||||||
|
res = xs_dict_append(res, "hashtags", htl);
|
||||||
|
|
||||||
|
*body = xs_json_dumps_pp(res, 4);
|
||||||
|
*ctype = "application/json";
|
||||||
|
status = 200;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
res = xs_dict_append(res, "accounts", acl);
|
status = 401;
|
||||||
res = xs_dict_append(res, "statuses", stl);
|
|
||||||
res = xs_dict_append(res, "hashtags", htl);
|
|
||||||
|
|
||||||
*body = xs_json_dumps_pp(res, 4);
|
|
||||||
*ctype = "application/json";
|
|
||||||
status = 200;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* user cleanup */
|
/* user cleanup */
|
||||||
|
|
Loading…
Reference in a new issue