|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
#include "collections/array.h"
|
|
|
|
|
#include "util/format.h"
|
|
|
|
|
#include "ap/object.h"
|
|
|
|
|
#include "ap/http.h"
|
|
|
|
|
|
|
|
|
|
// Model
|
|
|
|
|
#include "model/server.h"
|
|
|
|
@ -21,31 +22,55 @@ char* status_render_source( struct status* s );
|
|
|
|
|
// Route: /note/
|
|
|
|
|
bool route_ap_note( struct http_request* req )
|
|
|
|
|
{
|
|
|
|
|
struct status* s = NULL;
|
|
|
|
|
bool result = false;
|
|
|
|
|
char* id_str = http_request_route_get_dir_or_file(req);
|
|
|
|
|
if( !id_str || !*id_str ) { return false; }
|
|
|
|
|
if( !id_str || !*id_str ) { goto failed; }
|
|
|
|
|
|
|
|
|
|
// Route: /note/%d{id}
|
|
|
|
|
int id = -1;
|
|
|
|
|
if( 1 != sscanf( id_str, "%d", &id ) ) { return false; }
|
|
|
|
|
if( 1 != sscanf( id_str, "%d", &id ) ) { goto failed; }
|
|
|
|
|
free(id_str);
|
|
|
|
|
|
|
|
|
|
struct status* s = status_from_id( id );
|
|
|
|
|
if( !s ) { return false; }
|
|
|
|
|
if( s->remote ) { return false; }
|
|
|
|
|
s = status_from_id( id );
|
|
|
|
|
if( !s ) { goto failed; };
|
|
|
|
|
if( s->remote ) { goto failed; }
|
|
|
|
|
|
|
|
|
|
struct ap_object* act = activity_create_Note( s );
|
|
|
|
|
|
|
|
|
|
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );
|
|
|
|
|
http_request_send_headers( req, 200, "application/ld+json", true );
|
|
|
|
|
FILE* f = http_request_get_response_body( req );
|
|
|
|
|
ap_object_write_to_FILE( act, f );
|
|
|
|
|
fflush(f);
|
|
|
|
|
|
|
|
|
|
ap_object_free(act);
|
|
|
|
|
if( http_request_route_term(req,"") ) {
|
|
|
|
|
result = ap_object_handle_http_request( req, activity_create_Note(s), true, false );
|
|
|
|
|
if( !result ) {
|
|
|
|
|
struct account* poster = account_from_id( s->account_id );
|
|
|
|
|
if( !poster ) { goto failed; }
|
|
|
|
|
|
|
|
|
|
char location[512];
|
|
|
|
|
snprintf( location,sizeof(location), "/@%s@%s/posts/%018d", poster->handle, poster->server, s->id );
|
|
|
|
|
account_free(poster);
|
|
|
|
|
|
|
|
|
|
// TODO: redirect
|
|
|
|
|
http_request_begin_send_headers( req, 302, false );
|
|
|
|
|
|
|
|
|
|
http_request_send_header( req, "Location", location );
|
|
|
|
|
http_request_end_send_headers( req, false );
|
|
|
|
|
goto success;
|
|
|
|
|
}
|
|
|
|
|
goto cleanup;
|
|
|
|
|
} else if( http_request_route_term(req,"replies") ) {
|
|
|
|
|
if( s->replies.count > 0 ) {
|
|
|
|
|
result = ap_object_handle_http_request( req, status_replies_Collection(s), true, true );
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto failed;
|
|
|
|
|
cleanup:
|
|
|
|
|
status_free(s);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
return result;
|
|
|
|
|
failed:
|
|
|
|
|
result = false;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
success:
|
|
|
|
|
result = true;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Route: /activity/
|
|
|
|
@ -59,17 +84,7 @@ bool route_ap_activity( struct http_request* req )
|
|
|
|
|
if( 1 != sscanf( id_str, "%d", &id ) ) { return false; }
|
|
|
|
|
free(id_str);
|
|
|
|
|
|
|
|
|
|
struct ap_object* act = activity_from_local_id( id );
|
|
|
|
|
|
|
|
|
|
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );
|
|
|
|
|
http_request_send_headers( req, 200, "application/ld+json", true );
|
|
|
|
|
FILE* f = http_request_get_response_body( req );
|
|
|
|
|
ap_object_write_to_FILE( act, f );
|
|
|
|
|
fflush(f);
|
|
|
|
|
|
|
|
|
|
ap_object_free(act);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
return ap_object_handle_http_request( req, activity_from_local_id(id), true, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Route: /outbox
|
|
|
|
@ -79,28 +94,16 @@ bool route_ap_outbox( struct http_request* req )
|
|
|
|
|
struct account* owner_account = account_from_id( owner_account_id );
|
|
|
|
|
|
|
|
|
|
if( http_request_route_term(req,"") ) {
|
|
|
|
|
struct ap_object* outbox = account_ap_outbox( owner_account );
|
|
|
|
|
|
|
|
|
|
http_request_send_headers( req, 200, "application/ld+json", true );
|
|
|
|
|
FILE* f = http_request_get_response_body( req );
|
|
|
|
|
ap_object_write_to_FILE( outbox, f );
|
|
|
|
|
fflush(f);
|
|
|
|
|
result = ap_object_handle_http_request( req, account_ap_outbox(owner_account), true, true );
|
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
|
|
ap_object_free(outbox);
|
|
|
|
|
} else if( http_request_route( req, "/page-" ) ) {
|
|
|
|
|
char* page_str = http_request_route_get_dir_or_file(req);
|
|
|
|
|
int page = -1;
|
|
|
|
|
if( !page_str || (1 != sscanf(page_str,"%d",&page) ) || page < 0 ) { goto failed; }
|
|
|
|
|
|
|
|
|
|
struct ap_object* outbox_page = account_ap_outbox_page( owner_account, page );
|
|
|
|
|
if( !outbox_page ) { goto failed; }
|
|
|
|
|
|
|
|
|
|
http_request_send_headers( req, 200, "application/ld+json", true );
|
|
|
|
|
FILE* f = http_request_get_response_body( req );
|
|
|
|
|
ap_object_write_to_FILE( outbox_page, f );
|
|
|
|
|
fflush(f);
|
|
|
|
|
|
|
|
|
|
ap_object_free(outbox_page);
|
|
|
|
|
result = ap_object_handle_http_request( req, account_ap_outbox_page(owner_account,page), true, true );
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
goto success;
|
|
|
|
|
failed:
|
|
|
|
|