|
|
|
@ -13,26 +13,17 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
static bool handle_featured( struct http_request* req )
|
|
|
|
|
struct pager
|
|
|
|
|
{
|
|
|
|
|
struct account* owner_account = account_from_id(0);
|
|
|
|
|
|
|
|
|
|
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );
|
|
|
|
|
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"
|
|
|
|
|
void* data;
|
|
|
|
|
struct ap_object* (*get_root)( void* );
|
|
|
|
|
struct ap_object* (*get_page)( void*, int );
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
account_free( owner_account );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
static bool handle_followers( struct http_request* req )
|
|
|
|
|
static bool handle_paged_collection( struct http_request* req, struct pager* pg )
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
struct ap_object* obj = pg->get_root( pg->data );
|
|
|
|
|
|
|
|
|
|
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );
|
|
|
|
|
http_request_send_headers( req, 200, "application/activity+json", true );
|
|
|
|
@ -43,12 +34,12 @@ static bool handle_followers( struct http_request* req )
|
|
|
|
|
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; }
|
|
|
|
|
if( !page_str ) { return false; }
|
|
|
|
|
if( 1 != sscanf(page_str,"%d",&page) ) { return false; }
|
|
|
|
|
if( page < 0 ) { return false; }
|
|
|
|
|
|
|
|
|
|
struct ap_object* obj = account_ap_followers_page(owner_account,page);
|
|
|
|
|
if( !obj ) { goto failed; }
|
|
|
|
|
struct ap_object* obj = pg->get_page( pg->data, page );
|
|
|
|
|
if( !obj ) { return false; }
|
|
|
|
|
|
|
|
|
|
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );
|
|
|
|
|
http_request_send_headers( req, 200, "application/activity+json", true );
|
|
|
|
@ -56,63 +47,49 @@ static bool handle_followers( struct http_request* req )
|
|
|
|
|
ap_object_write_to_FILE( obj, f );
|
|
|
|
|
ap_object_free(obj);
|
|
|
|
|
}
|
|
|
|
|
goto success;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
account_free( owner_account );
|
|
|
|
|
static bool handle_featured( struct http_request* req )
|
|
|
|
|
{
|
|
|
|
|
struct account* owner_account = account_from_id(0);
|
|
|
|
|
|
|
|
|
|
struct pager pg = {
|
|
|
|
|
.data = owner_account,
|
|
|
|
|
.get_root = (void*)account_ap_featured,
|
|
|
|
|
.get_page = (void*)account_ap_featured_page,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool result = handle_paged_collection(req,&pg);
|
|
|
|
|
account_free( owner_account );
|
|
|
|
|
return result;
|
|
|
|
|
success:
|
|
|
|
|
result = true;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
failed:
|
|
|
|
|
printf( "! failed\n" );
|
|
|
|
|
result = false;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
static bool handle_following( struct http_request* req )
|
|
|
|
|
static bool handle_followers( struct http_request* req )
|
|
|
|
|
{
|
|
|
|
|
printf( "handle_following\n" );
|
|
|
|
|
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);
|
|
|
|
|
struct pager pg = {
|
|
|
|
|
.data = owner_account,
|
|
|
|
|
.get_root = (void*)account_ap_followers,
|
|
|
|
|
.get_page = (void*)account_ap_followers_page,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );
|
|
|
|
|
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; }
|
|
|
|
|
bool result = handle_paged_collection(req,&pg);
|
|
|
|
|
account_free( owner_account );
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
static bool handle_following( struct http_request* req )
|
|
|
|
|
{
|
|
|
|
|
struct account* owner_account = account_from_id(0);
|
|
|
|
|
|
|
|
|
|
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
struct pager pg = {
|
|
|
|
|
.data = owner_account,
|
|
|
|
|
.get_root = (void*)account_ap_following,
|
|
|
|
|
.get_page = (void*)account_ap_following_page,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
goto success;
|
|
|
|
|
success:
|
|
|
|
|
result = true;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
failed:
|
|
|
|
|
printf( "! failed\n" );
|
|
|
|
|
result = false;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
cleanup:
|
|
|
|
|
bool result = handle_paged_collection(req,&pg);
|
|
|
|
|
account_free( owner_account );
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|