Refactor routing for statuses

master
teknomunk 1 year ago
parent f19ea54b1d
commit 4344b9dac6

@ -1 +1 @@
Subproject commit 54ff2ecda5cd74f5c1b6e2a14cc47360af9d0628
Subproject commit af6ffed1c98d57b754692ab8f55467a5215a3bd2

@ -67,9 +67,9 @@ void show_status_context( struct http_request* req, struct status* s )
fprintf( f, "{\"ancestors\":[" );
for( int i = 0; i < ancestors.count; ++i ) {
struct status* s = ancestors.items[i];
api_status_write_as_json(s,f);
status_free(s);
struct status* s2 = ancestors.items[i];
api_status_write_as_json(s2,f);
status_free(s2);
if( i != ancestors.count - 1 ) {
fprintf( f, "," );
@ -79,9 +79,9 @@ void show_status_context( struct http_request* req, struct status* s )
fprintf( f, "],\"descendants\":[" );
for( int i = 0; i < replies.count; ++i ) {
struct status* s = replies.items[i];
api_status_write_as_json(s,f);
status_free(s);
struct status* s2 = replies.items[i];
api_status_write_as_json(s2,f);
status_free(s2);
if( i != replies.count - 1 ) {
fprintf( f, "," );

@ -214,6 +214,44 @@ bool http_request_route_id( struct http_request* req, int* id )
return true;
}
// Route: /api/v1/statuses/%d{id}/
bool route_statuses_1f( struct http_request* req )
{
bool result = false;
struct status* s = NULL;
if( http_request_route( req, "" ) && http_request_route_method( req, "POST" ) ) {
struct account* owner = account_from_id(0);
bool res = handle_post(req, owner);
account_free(owner);
return res;
}
if( !http_request_route( req, "/" ) ) { return false; }
int id = -1;
if( !http_request_route_id( req, &id ) ) { goto failed; }
s = status_from_id(id);
if( !s ) { goto failed; }
if( http_request_route( req, "context" ) ) {
show_status_context( req, s );
goto success;
} else if( http_request_route( req, "" ) ) {
show_status( req, s );
goto success;
}
failed:
result = false;
cleanup:
status_free(s);
return result;
success:
result = true;
goto cleanup;
}
bool route_mastodon_api( struct http_request* req )
{
if( http_request_route_term( req, "apps" ) ) {
@ -243,30 +281,7 @@ bool route_mastodon_api( struct http_request* req )
fprintf( f, "[]" );
return true;
} else if( http_request_route( req, "statuses" ) ) {
printf( "route: statuses\n" );
if( http_request_route( req, "/" ) ) {
int id = -1;
if( http_request_route_id( req, &id ) ) {
struct status* s = status_from_id(id);
if( !s ) {
return false;
}
if( http_request_route( req, "context" ) ) {
show_status_context( req, s );
} else {
show_status( req, s );
}
status_free(s);
return true;
}
} else if( http_request_route_method( req, "POST" ) ) {
struct account* owner = account_from_id(0);
bool res = handle_post(req, owner);
account_free(owner);
return res;
}
return route_statuses_1f(req);
} else if( http_request_route( req, "timelines/" ) ) {
if( http_request_route( req, "home" ) ) {
return handle_timeline( req, tli_home );

Loading…
Cancel
Save