You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
4.3 KiB
C
169 lines
4.3 KiB
C
#include "owner.h"
|
|
|
|
// Submodules
|
|
#include "http/server/request.h"
|
|
#include "ap/object.h"
|
|
|
|
// Model
|
|
#include "model/server.h"
|
|
|
|
// View
|
|
#include "view/layout.h"
|
|
|
|
// Standard Library
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static bool handle_featured( struct http_request* req )
|
|
{
|
|
struct account* owner_account = account_from_id(0);
|
|
|
|
http_request_send_headers( req, 200, "application/activity+json", true );
|
|
FILE* f = http_request_get_response_body(req);
|
|
#include "src/view/owner/featured.json.inc"
|
|
|
|
account_free( owner_account );
|
|
|
|
return true;
|
|
}
|
|
static bool handle_followers( struct http_request* req )
|
|
{
|
|
bool result = false;
|
|
struct account* owner_account = account_from_id(0);
|
|
|
|
if( http_request_route_term(req,"") ) {
|
|
struct ap_object* obj = account_ap_followers(owner_account);
|
|
|
|
http_request_send_headers( req, 200, "application/activity+json", true );
|
|
FILE* f = http_request_get_response_body(req);
|
|
ap_object_write_to_FILE( obj, f );
|
|
ap_object_free(obj);
|
|
} else if( http_request_route( req, "/page-" ) ) {
|
|
printf( "/page-\n" );
|
|
char* page_str = http_request_route_get_dir_or_file(req);
|
|
int page = -1;
|
|
if( !page_str ) { goto failed; }
|
|
if( 1 != sscanf(page_str,"%d",&page) ) { goto failed; }
|
|
if( page < 0 ) { goto failed; }
|
|
|
|
struct ap_object* obj = account_ap_followers_page(owner_account,page);
|
|
if( !obj ) { goto failed; }
|
|
|
|
http_request_send_headers( req, 200, "application/activity+json", true );
|
|
FILE* f = http_request_get_response_body(req);
|
|
ap_object_write_to_FILE( obj, f );
|
|
ap_object_free(obj);
|
|
}
|
|
|
|
succeded:
|
|
result = true;
|
|
goto cleanup;
|
|
failed:
|
|
printf( "! failed\n" );
|
|
result = false;
|
|
goto cleanup;
|
|
cleanup:
|
|
account_free( owner_account );
|
|
|
|
return result;
|
|
}
|
|
static bool handle_following( struct http_request* req )
|
|
{
|
|
bool result = false;
|
|
struct account* owner_account = account_from_id(0);
|
|
|
|
if( http_request_route_term(req,"") ) {
|
|
struct ap_object* obj = account_ap_following(owner_account);
|
|
|
|
http_request_send_headers( req, 200, "application/activity+json", true );
|
|
FILE* f = http_request_get_response_body(req);
|
|
ap_object_write_to_FILE( obj, f );
|
|
ap_object_free(obj);
|
|
} else if( http_request_route( req, "/page-" ) ) {
|
|
printf( "/page-\n" );
|
|
char* page_str = http_request_route_get_dir_or_file(req);
|
|
int page = -1;
|
|
if( !page_str ) { goto failed; }
|
|
if( 1 != sscanf(page_str,"%d",&page) ) { goto failed; }
|
|
if( page < 0 ) { goto failed; }
|
|
|
|
struct ap_object* obj = account_ap_following_page(owner_account,page);
|
|
if( !obj ) { goto failed; }
|
|
|
|
http_request_send_headers( req, 200, "application/activity+json", true );
|
|
FILE* f = http_request_get_response_body(req);
|
|
ap_object_write_to_FILE( obj, f );
|
|
ap_object_free(obj);
|
|
}
|
|
|
|
succeded:
|
|
result = true;
|
|
goto cleanup;
|
|
failed:
|
|
printf( "! failed\n" );
|
|
result = false;
|
|
goto cleanup;
|
|
cleanup:
|
|
account_free( owner_account );
|
|
|
|
return result;
|
|
}
|
|
|
|
static bool handle_owner_actor( struct http_request* req )
|
|
{
|
|
struct account* owner_account = account_from_id(0);
|
|
|
|
http_request_send_headers( req, 200, "application/activity+json", true );
|
|
FILE* f = http_request_get_response_body(req);
|
|
|
|
struct ap_object* obj = account_ap_actor( owner_account );
|
|
ap_object_write_to_FILE( obj, f );
|
|
ap_object_free(obj);
|
|
|
|
account_free( owner_account );
|
|
return true;
|
|
}
|
|
|
|
static bool handle_avatar( struct http_request* req )
|
|
{
|
|
FILE* f = fopen("data/owner/avatar.png","r");
|
|
if( f ) {
|
|
fclose(f);
|
|
return http_request_send_file( req, "data/owner/avatar.png", "image/png" );
|
|
}
|
|
|
|
return false;
|
|
}
|
|
static bool handle_banner( struct http_request* req )
|
|
{
|
|
FILE* f = fopen("data/owner/banner.png","r");
|
|
if( f ) {
|
|
fclose(f);
|
|
return http_request_send_file( req, "data/owner/banner.png", "image/png" );
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool route_owner( struct http_request* req )
|
|
{
|
|
if( http_request_route( req, "/actor" ) ) {
|
|
if( http_request_route_term( req, "" ) ) {
|
|
return handle_owner_actor(req);
|
|
}
|
|
} else if( http_request_route_term( req, "/following" ) ) {
|
|
return handle_following(req);
|
|
} else if( http_request_route( req, "/followers" ) ) {
|
|
return handle_followers(req);
|
|
} else if( http_request_route_term( req, "/collections/featured" ) ) {
|
|
return handle_featured(req);
|
|
} else if( http_request_route_term( req, "/avatar.blob" ) ) {
|
|
return handle_avatar(req);
|
|
} else if( http_request_route_term( req, "/banner.blob" ) ) {
|
|
return handle_banner(req);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|