Slon/Api/V2: Add initial support for Search endpoint
This commit is contained in:
parent
8730286ca1
commit
9260e8ee2a
4 changed files with 58 additions and 0 deletions
52
Slon/Api/V2/Search.HC
Normal file
52
Slon/Api/V2/Search.HC
Normal file
|
@ -0,0 +1,52 @@
|
|||
U0 @slon_api_v2_search_get(SlonHttpSession* session)
|
||||
{
|
||||
SLON_SCRATCH_BUFFER_AND_REQUEST_JSON
|
||||
|
||||
if (@slon_api_authorized(session)) {
|
||||
// SLON_AUTH_ACCOUNT_ID
|
||||
// FIXME: Implement this
|
||||
JsonObject* results = Json.CreateObject();
|
||||
results->set("accounts", Json.CreateArray(), JSON_ARRAY);
|
||||
results->set("statuses", Json.CreateArray(), JSON_ARRAY);
|
||||
results->set("hashtags", Json.CreateArray(), JSON_ARRAY);
|
||||
|
||||
U8* q = request_json->@("q");
|
||||
if (!q) {
|
||||
goto slon_api_v2_search_get_return;
|
||||
}
|
||||
|
||||
if (q[0] == '@' || StrFind("@", request_json->@("q")) > 0) {
|
||||
// if "type" is specified, value must be "accounts"
|
||||
// if "resolve" is TRUE, do WebFinger lookup if the remote account doesn't exist on this server
|
||||
I64 at_fragment_count = 0;
|
||||
U8* q_copy = @slon_strnew(session, q);
|
||||
U8** at_fragments = String.Split(q_copy, '@', &at_fragment_count);
|
||||
|
||||
switch (at_fragment_count) {
|
||||
case 2:
|
||||
// Local user
|
||||
// break;
|
||||
case 3:
|
||||
// Remote user
|
||||
StrPrint(scratch_buffer, "%s@%s", at_fragments[0], at_fragments[1]);
|
||||
JsonObject* remote_account = @slon_api_account_by_acct(scratch_buffer);
|
||||
if (remote_account) {
|
||||
results->a("accounts")->append(Json.CreateItem(remote_account, JSON_OBJECT));
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Unsupported
|
||||
break;
|
||||
}
|
||||
|
||||
@slon_free(session, q_copy);
|
||||
}
|
||||
|
||||
slon_api_v2_search_get_return:
|
||||
@slon_http_send_json(session, results);
|
||||
Json.Delete(results);
|
||||
} else {
|
||||
@slon_http_set_status_code(session, 401);
|
||||
}
|
||||
}
|
4
Slon/Endpoints/Get/Search.HC
Normal file
4
Slon/Endpoints/Get/Search.HC
Normal file
|
@ -0,0 +1,4 @@
|
|||
if (!StrICmp("/api/v2/search", @slon_http_request_path(session))) {
|
||||
@slon_api_v2_search_get(session);
|
||||
return;
|
||||
}
|
|
@ -405,6 +405,7 @@ U0 @slon_http_handle_get_request(SlonHttpSession* session)
|
|||
#include "Endpoints/Get/Instance";
|
||||
#include "Endpoints/Get/Notifications";
|
||||
#include "Endpoints/Get/OAuth";
|
||||
#include "Endpoints/Get/Search";
|
||||
#include "Endpoints/Get/Suggestions";
|
||||
#include "Endpoints/Get/Timelines";
|
||||
#include "Endpoints/Get/Web";
|
||||
|
|
|
@ -24,6 +24,7 @@ WinMax(Fs);
|
|||
|
||||
#include "Api/V2/Filters";
|
||||
#include "Api/V2/Instance";
|
||||
#include "Api/V2/Search";
|
||||
#include "Api/V2/Suggestions";
|
||||
|
||||
#include "Modules/ActivityPub";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue