Slon/Api/V1/Statuses: Allow retrieval of individual status from public timeline
This commit is contained in:
parent
715d119882
commit
5258ab19a8
4 changed files with 72 additions and 53 deletions
|
@ -94,7 +94,7 @@ JsonArray* @slon_api_v1_statuses_lookup_descendants_by_id(U8* id, JsonArray* sta
|
||||||
|
|
||||||
JsonObject* @slon_api_v1_statuses_find_by_id(U8* id, U8* account_id)
|
JsonObject* @slon_api_v1_statuses_find_by_id(U8* id, U8* account_id)
|
||||||
{
|
{
|
||||||
if (!id || !account_id) {
|
if (!id) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
JsonObject* status = NULL;
|
JsonObject* status = NULL;
|
||||||
|
@ -103,6 +103,9 @@ JsonObject* @slon_api_v1_statuses_find_by_id(U8* id, U8* account_id)
|
||||||
if (status) {
|
if (status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
if (!account_id) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
// Then, lookup in home timeline
|
// Then, lookup in home timeline
|
||||||
status = @slon_api_v1_statuses_lookup_by_id(id, db->o("timelines")->o("home")->a(account_id));
|
status = @slon_api_v1_statuses_lookup_by_id(id, db->o("timelines")->o("home")->a(account_id));
|
||||||
if (status) {
|
if (status) {
|
||||||
|
@ -274,8 +277,6 @@ U0 @slon_api_v1_statuses_delete(SlonHttpSession* session)
|
||||||
|
|
||||||
U0 @slon_api_v1_statuses_get(SlonHttpSession* session)
|
U0 @slon_api_v1_statuses_get(SlonHttpSession* session)
|
||||||
{
|
{
|
||||||
if (@slon_api_authorized(session)) {
|
|
||||||
SLON_AUTH_ACCOUNT_ID
|
|
||||||
|
|
||||||
if (session->path_count() < 4) {
|
if (session->path_count() < 4) {
|
||||||
session->status(400);
|
session->status(400);
|
||||||
|
@ -291,6 +292,9 @@ U0 @slon_api_v1_statuses_get(SlonHttpSession* session)
|
||||||
U8* id = session->path(3);
|
U8* id = session->path(3);
|
||||||
JsonObject* status = NULL;
|
JsonObject* status = NULL;
|
||||||
|
|
||||||
|
if (@slon_api_authorized(session)) {
|
||||||
|
SLON_AUTH_ACCOUNT_ID
|
||||||
|
|
||||||
if (session->path_count() > 4 && !StrICmp("context", session->path(4))) {
|
if (session->path_count() > 4 && !StrICmp("context", session->path(4))) {
|
||||||
JsonObject* context = Json.CreateObject();
|
JsonObject* context = Json.CreateObject();
|
||||||
context->set("ancestors", Json.CreateArray(), JSON_ARRAY);
|
context->set("ancestors", Json.CreateArray(), JSON_ARRAY);
|
||||||
|
@ -321,7 +325,12 @@ U0 @slon_api_v1_statuses_get(SlonHttpSession* session)
|
||||||
}
|
}
|
||||||
session->status(404);
|
session->status(404);
|
||||||
} else {
|
} else {
|
||||||
session->status(401);
|
status = @slon_api_v1_statuses_find_by_id(id, NULL);
|
||||||
|
if (status) {
|
||||||
|
session->send(status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
session->status(404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,11 @@ U0 @slon_web_user_get(SlonHttpSession* session)
|
||||||
U8** path_segments = String.Split(StrFind("@", session->path()) + 1, '/', &path_segments_count);
|
U8** path_segments = String.Split(StrFind("@", session->path()) + 1, '/', &path_segments_count);
|
||||||
|
|
||||||
U8* user = path_segments[0];
|
U8* user = path_segments[0];
|
||||||
|
|
||||||
if (path_segments_count == 1) {
|
|
||||||
JsonObject* actor = db->o("actors")->@(user);
|
JsonObject* actor = db->o("actors")->@(user);
|
||||||
if (!actor) {
|
if (!actor) {
|
||||||
session->status(404);
|
session->status(404);
|
||||||
goto slon_web_user_get_return;
|
goto slon_web_user_get_return;
|
||||||
}
|
}
|
||||||
// gib profil pl0x
|
|
||||||
|
|
||||||
I64 html_file_size;
|
I64 html_file_size;
|
||||||
U8* html_file_data = FileRead("M:/Slon/Static/html/user.html", &html_file_size);
|
U8* html_file_data = FileRead("M:/Slon/Static/html/user.html", &html_file_size);
|
||||||
|
@ -22,7 +19,16 @@ U0 @slon_web_user_get(SlonHttpSession* session)
|
||||||
|
|
||||||
U8* html_data = @slon_calloc(session, (html_file_size * 2) + (StrLen(user_file_data) * 2));
|
U8* html_data = @slon_calloc(session, (html_file_size * 2) + (StrLen(user_file_data) * 2));
|
||||||
String.Append(html_data, html_file_data);
|
String.Append(html_data, html_file_data);
|
||||||
|
|
||||||
|
switch (path_segments_count) {
|
||||||
|
case 1:
|
||||||
String.Append(html_data, "<script>getStatuses(");
|
String.Append(html_data, "<script>getStatuses(");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
String.Append(html_data, "<script>getStatusById(\"%s\",", path_segments[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
String.Append(html_data, user_file_data);
|
String.Append(html_data, user_file_data);
|
||||||
String.Append(html_data, ");</script>");
|
String.Append(html_data, ");</script>");
|
||||||
session->content_type("text/html");
|
session->content_type("text/html");
|
||||||
|
@ -31,11 +37,6 @@ U0 @slon_web_user_get(SlonHttpSession* session)
|
||||||
Free(html_file_data);
|
Free(html_file_data);
|
||||||
Free(user_file_data);
|
Free(user_file_data);
|
||||||
@slon_free(session, html_data);
|
@slon_free(session, html_data);
|
||||||
goto slon_web_user_get_return;
|
|
||||||
} else {
|
|
||||||
// do something here (statuses, followers, media, etc.)
|
|
||||||
session->status(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
slon_web_user_get_return:
|
slon_web_user_get_return:
|
||||||
Free(path_segments);
|
Free(path_segments);
|
||||||
|
|
|
@ -26,4 +26,4 @@
|
||||||
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/plugin/relativeTime.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/plugin/relativeTime.js"></script>
|
||||||
<script>dayjs.extend(window.dayjs_plugin_relativeTime)</script>
|
<script>dayjs.extend(window.dayjs_plugin_relativeTime)</script>
|
||||||
<script src=https://error.checksum.fail/js/header.js></script>
|
<script src=https://error.checksum.fail/js/header.js></script>
|
||||||
<script src=https://error.checksum.fail/js/29137902173921730271.js></script>
|
<script src=https://error.checksum.fail/js/91274902173.js></script>
|
|
@ -136,3 +136,12 @@ function getStatuses(user) {
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => updateStatuses(user, data));
|
.then(data => updateStatuses(user, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getStatusById(id, user) {
|
||||||
|
fetch("https://error.checksum.fail/api/v1/statuses/" + id, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { 'Accept': 'application/json' }
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => updateStatuses(user, [data]));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue