Slon/Api/V1/Markers: Implement /api/v1/markers
This commit is contained in:
parent
e223273300
commit
95aecb9fb1
6 changed files with 93 additions and 0 deletions
48
Slon/Api/V1/Markers.HC
Normal file
48
Slon/Api/V1/Markers.HC
Normal file
|
@ -0,0 +1,48 @@
|
|||
U0 @slon_api_v1_markers_get(SlonHttpSession* session)
|
||||
{
|
||||
if (!@slon_api_authorized(session)) {
|
||||
session->status(401);
|
||||
return;
|
||||
}
|
||||
|
||||
SLON_AUTH_ACCOUNT_ID
|
||||
|
||||
if (db->o("markers")->@(account_id)) {
|
||||
session->send(db->o("markers")->@(account_id));
|
||||
} else {
|
||||
session->send(SLON_EMPTY_JSON_OBJECT);
|
||||
}
|
||||
}
|
||||
|
||||
U0 @slon_api_v1_markers_post(SlonHttpSession* session)
|
||||
{
|
||||
if (!@slon_api_authorized(session)) {
|
||||
session->status(401);
|
||||
return;
|
||||
}
|
||||
|
||||
SLON_SCRATCH_BUFFER_AND_REQUEST_JSON
|
||||
no_warn scratch_buffer;
|
||||
|
||||
SLON_AUTH_ACCOUNT_ID
|
||||
|
||||
U8* updated_at = @slon_api_timestamp_from_cdate(session, Now);
|
||||
|
||||
JsonKey* key = request_json->keys;
|
||||
JsonObject* obj = NULL;
|
||||
I64 version = cnts.jiffies;
|
||||
while (key) {
|
||||
obj = key->value;
|
||||
if (obj) {
|
||||
obj->set("version", version, JSON_NUMBER);
|
||||
obj->set("updated_at", updated_at, JSON_STRING);
|
||||
}
|
||||
key = key->next;
|
||||
}
|
||||
|
||||
db->o("markers")->set(account_id, request_json, JSON_OBJECT);
|
||||
@slon_db_save_markers_to_disk;
|
||||
|
||||
session->send(request_json);
|
||||
@slon_free(session, updated_at);
|
||||
}
|
4
Slon/Endpoints/Get/Markers.HC
Normal file
4
Slon/Endpoints/Get/Markers.HC
Normal file
|
@ -0,0 +1,4 @@
|
|||
if (!StrICmp("/api/v1/markers", session->path())) {
|
||||
@slon_api_v1_markers_get(session);
|
||||
return;
|
||||
}
|
4
Slon/Endpoints/Post/Markers.HC
Normal file
4
Slon/Endpoints/Post/Markers.HC
Normal file
|
@ -0,0 +1,4 @@
|
|||
if (!StrICmp("/api/v1/markers", session->path())) {
|
||||
@slon_api_v1_markers_post(session);
|
||||
return;
|
||||
}
|
|
@ -526,6 +526,7 @@ U0 @slon_http_handle_get_request(SlonHttpSession* session)
|
|||
#include "Endpoints/Get/FollowRequests";
|
||||
#include "Endpoints/Get/FollowedTags";
|
||||
#include "Endpoints/Get/Instance";
|
||||
#include "Endpoints/Get/Markers";
|
||||
#include "Endpoints/Get/Notifications";
|
||||
#include "Endpoints/Get/NodeInfo";
|
||||
#include "Endpoints/Get/OAuth";
|
||||
|
@ -587,6 +588,7 @@ U0 @slon_http_handle_post_request(SlonHttpSession* session)
|
|||
#include "Endpoints/Post/Accounts";
|
||||
#include "Endpoints/Post/ActivityPub";
|
||||
#include "Endpoints/Post/Apps";
|
||||
#include "Endpoints/Post/Markers";
|
||||
#include "Endpoints/Post/OAuth";
|
||||
#include "Endpoints/Post/Statuses";
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ WinMax(Fs);
|
|||
#include "Api/V1/Filters";
|
||||
#include "Api/V1/FollowRequests";
|
||||
#include "Api/V1/FollowedTags";
|
||||
#include "Api/V1/Markers";
|
||||
#include "Api/V1/Notifications";
|
||||
#include "Api/V1/Statuses";
|
||||
#include "Api/V1/Timelines";
|
||||
|
|
|
@ -86,6 +86,26 @@ U0 @slon_db_load_following_from_disk()
|
|||
db->set("following", following, JSON_OBJECT);
|
||||
}
|
||||
|
||||
U0 @slon_db_load_markers_from_disk()
|
||||
{
|
||||
JsonObject* markers = Json.CreateObject();
|
||||
U8 scratch_buffer[256];
|
||||
StrPrint(scratch_buffer, "%s/markers/*.json", SLON_DB_PATH);
|
||||
CDirEntry* files = FilesFind(scratch_buffer);
|
||||
CDirEntry* de = files;
|
||||
JsonArray* marker_array = NULL;
|
||||
while (de) {
|
||||
marker_array = Json.ParseFile(de->full_name);
|
||||
if (marker_array) {
|
||||
StrFind(".json", de->name)[0] = NULL;
|
||||
markers->set(de->name, marker_array, JSON_ARRAY);
|
||||
}
|
||||
de = de->next;
|
||||
}
|
||||
DirTreeDel(files);
|
||||
db->set("markers", markers, JSON_OBJECT);
|
||||
}
|
||||
|
||||
U0 @slon_db_load_statuses_from_disk()
|
||||
{
|
||||
JsonObject* statuses = Json.CreateObject();
|
||||
|
@ -196,6 +216,17 @@ U0 @slon_db_save_following_to_disk()
|
|||
}
|
||||
}
|
||||
|
||||
U0 @slon_db_save_markers_to_disk()
|
||||
{
|
||||
U8 scratch_buffer[256];
|
||||
JsonKey* key = db->o("markers")->keys;
|
||||
while (key) {
|
||||
StrPrint(scratch_buffer, "%s/markers/%s.json", SLON_DB_PATH, key->name);
|
||||
Json.DumpToFile(scratch_buffer, key->value);
|
||||
key = key->next;
|
||||
}
|
||||
}
|
||||
|
||||
U0 @slon_db_save_statuses_to_disk()
|
||||
{
|
||||
U8 scratch_buffer[256];
|
||||
|
@ -228,6 +259,7 @@ U0 @slon_db_save_to_disk()
|
|||
@slon_db_save_followers_to_disk();
|
||||
@slon_db_save_following_to_disk();
|
||||
@slon_db_save_instance_to_disk();
|
||||
@slon_db_save_markers_to_disk();
|
||||
@slon_db_save_oauth_to_disk();
|
||||
@slon_db_save_private_keys_to_disk();
|
||||
@slon_db_save_statuses_to_disk();
|
||||
|
@ -246,6 +278,7 @@ U0 @slon_db_load_from_defaults()
|
|||
db->set("followers", Json.CreateObject(), JSON_OBJECT);
|
||||
db->set("following", Json.CreateObject(), JSON_OBJECT);
|
||||
db->set("instance", Json.ParseFile("M:/Slon/Static/defaults/instance.json"), JSON_OBJECT);
|
||||
db->set("markers", Json.CreateObject(), JSON_OBJECT);
|
||||
db->set("statuses", Json.CreateObject(), JSON_OBJECT);
|
||||
db->set("timelines", Json.CreateObject(), JSON_OBJECT);
|
||||
db->o("timelines")->set("home", Json.CreateObject(), JSON_OBJECT);
|
||||
|
@ -271,6 +304,7 @@ U0 @slon_db_load_from_disk()
|
|||
@slon_db_load_followers_from_disk();
|
||||
@slon_db_load_following_from_disk();
|
||||
@slon_db_load_instance_from_disk();
|
||||
@slon_db_load_markers_from_disk();
|
||||
@slon_db_load_oauth_from_disk();
|
||||
@slon_db_load_statuses_from_disk();
|
||||
@slon_db_load_timelines_from_disk();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue