Slon/Api/V1/Statuses: Allow retrieval of individual status from public timeline

This commit is contained in:
Alec Murphy 2025-03-02 18:07:09 -05:00
parent 715d119882
commit 5258ab19a8
4 changed files with 72 additions and 53 deletions

View file

@ -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);
} }
} }

View file

@ -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);

View file

@ -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>

View file

@ -38,7 +38,7 @@ function updateStatusContainers() {
} }
} }
function smolDate(a){return a.split(" ago")[0].replace("a ","1").replace("an ","1").replace("days","d").replace("day","d").replace("hours","h").replace("hour","h").replace("minutes","m").replace("minute","m").replace("seconds","s").replace("second","s").replace("few","").replace(" ","")}; function smolDate(a) { return a.split(" ago")[0].replace("a ", "1").replace("an ", "1").replace("days", "d").replace("day", "d").replace("hours", "h").replace("hour", "h").replace("minutes", "m").replace("minute", "m").replace("seconds", "s").replace("second", "s").replace("few", "").replace(" ", "") };
function updateStatuses(user, statuses) { function updateStatuses(user, statuses) {
let pageContent = document.getElementsByClassName("page-content")[0]; let pageContent = document.getElementsByClassName("page-content")[0];
@ -54,7 +54,7 @@ function updateStatuses(user, statuses) {
content_html += "<div class=status-avatar style=margin:16px;background:url(" + user["icon"]["url"] + ");width:72px;height:72px;background-size:contain;background-repeat:no-repeat></div>"; content_html += "<div class=status-avatar style=margin:16px;background:url(" + user["icon"]["url"] + ");width:72px;height:72px;background-size:contain;background-repeat:no-repeat></div>";
content_html += "<div class=status-header>" + user["preferredUsername"] + "<br><a href=" + user["url"] + ">@" + user["preferredUsername"] + "@" + location.host + "</a></div>" content_html += "<div class=status-header>" + user["preferredUsername"] + "<br><a href=" + user["url"] + ">@" + user["preferredUsername"] + "@" + location.host + "</a></div>"
content_html += "<div class=status-text><font style=color:#0>" + user["summary"] + "</font></div>"; content_html += "<div class=status-text><font style=color:#0>" + user["summary"] + "</font></div>";
content_html += "<div class=status-text>Joined " + new Date(Date.parse(user["published"])).toString().substr(0,15) + "</div>"; content_html += "<div class=status-text>Joined " + new Date(Date.parse(user["published"])).toString().substr(0, 15) + "</div>";
content.innerHTML = content_html; content.innerHTML = content_html;
let url = document.createElement('url'); let url = document.createElement('url');
url.textContent = window.location; url.textContent = window.location;
@ -70,7 +70,7 @@ function updateStatuses(user, statuses) {
} }
elements.className = "statuses"; elements.className = "statuses";
statuses.sort((a,b) => b.id - a.id); statuses.sort((a, b) => b.id - a.id);
for (var i = 0; i < statuses.length; i++) { for (var i = 0; i < statuses.length; i++) {
let status = statuses[i]; let status = statuses[i];
let container = document.createElement('div'); let container = document.createElement('div');
@ -131,8 +131,17 @@ function updateStatuses(user, statuses) {
function getStatuses(user) { function getStatuses(user) {
fetch("https://error.checksum.fail/api/v1/accounts/" + user["accountId"] + "/statuses", { fetch("https://error.checksum.fail/api/v1/accounts/" + user["accountId"] + "/statuses", {
method: 'GET', method: 'GET',
headers: {'Accept': 'application/json' } headers: { 'Accept': 'application/json' }
}) })
.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]));
}