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.
100 lines
2.4 KiB
C
100 lines
2.4 KiB
C
#include "owner.h"
|
|
|
|
#include "http_server/http_request.h"
|
|
|
|
#include "model/server.h"
|
|
|
|
#include "view/layout.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static void write_public_key( FILE* f )
|
|
{
|
|
FILE* pubkey = fopen( "data/owner/public.pem", "r" );
|
|
char ch;
|
|
while( (ch = fgetc(pubkey)) != EOF ) {
|
|
if( ch == '\n' ) {
|
|
fprintf( f, "\\n" );
|
|
} else {
|
|
fputc(ch,f);
|
|
}
|
|
}
|
|
}
|
|
|
|
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"
|
|
|
|
return true;
|
|
}
|
|
static bool handle_followers( 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/followers.json.inc"
|
|
|
|
return true;
|
|
}
|
|
static bool handle_following( 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/following.json.inc"
|
|
|
|
return true;
|
|
}
|
|
|
|
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);
|
|
#include "src/view/owner/actor.json.inc"
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool show_owner_profile_page( struct http_request* req )
|
|
{
|
|
struct account* account = account_from_id(0);
|
|
const char* title = "Apogee";
|
|
|
|
http_request_send_headers( req, 200, "text/html", true );
|
|
FILE* f = http_request_get_response_body(req);
|
|
#define RENDER
|
|
#include "src/view/account_page.html.inc"
|
|
#undef RENDER
|
|
|
|
return true;
|
|
}
|
|
|
|
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_term( 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, "" ) ) {
|
|
return show_owner_profile_page(req);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|