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.
132 lines
3.0 KiB
C
132 lines
3.0 KiB
C
#include "pleroma_api.h"
|
|
|
|
#include "http/cgi.h"
|
|
#include "http/server/request.h"
|
|
|
|
#include "model/account.h"
|
|
#include "model/status.h"
|
|
|
|
#include "src/controller/api/client_apps.h"
|
|
#include "src/controller/api/status.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
bool http_request_route_id( struct http_request* req, int* id );
|
|
|
|
// Route: /api/v1/pleroma/statuses/%d{s->id}/quotes
|
|
void show_status_quotes( struct http_request* req, struct status* s )
|
|
{
|
|
struct {
|
|
struct status** items;
|
|
int count;
|
|
} quotes;
|
|
|
|
status_get_quotes( s, "es );
|
|
printf( "Got %d statuses\n", quotes.count );
|
|
|
|
show_statuses( req, quotes.items, quotes.count );
|
|
}
|
|
|
|
// Route: /api/v1/pleroma/statuses/reactions/
|
|
static bool handle_reactions( struct http_request* req, struct status* s )
|
|
{
|
|
int method = -1;
|
|
if( http_request_route_method( req, "PUT" ) ) {
|
|
method = 1;
|
|
} else if( http_request_route_method( req, "DELETE" ) ) {
|
|
method = 0;
|
|
}
|
|
|
|
if( method != -1 ) {
|
|
char* react_cgi = http_request_route_get_dir_or_file( req );
|
|
char* react = cgi_unescape(react_cgi);
|
|
free(react_cgi);
|
|
|
|
// Make sure there is a reaction here
|
|
if( !*react ) {
|
|
return false;
|
|
}
|
|
|
|
struct account* owner = account_from_id( owner_account_id );
|
|
if( method ) {
|
|
status_add_react( s, react, owner );
|
|
} else {
|
|
status_remove_react( s, react, owner );
|
|
}
|
|
free(react);
|
|
account_free(owner);
|
|
|
|
show_status( req, s );
|
|
|
|
return true;
|
|
} else if( http_request_route_method( req, "GET" ) ) {
|
|
printf( "TODO: get who react information\n" );
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Route: /api/v1/pleroma/statuses
|
|
static bool route_status( struct http_request* req, struct status* s )
|
|
{
|
|
printf( __FILE__ " route_status. Remaining: '%s'\n", http_request_get_remaining_path(req) );
|
|
if( http_request_route( req, "reactions/" ) ) {
|
|
return handle_reactions( req, s );
|
|
} else if( http_request_route_term( req, "quotes" ) ) {
|
|
printf( __FILE__ " quotes\n" );
|
|
show_status_quotes( req, s );
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Route: /api/pleroma/frontend_configurations
|
|
static bool handle_frontend_configurations( struct http_request* req )
|
|
{
|
|
http_request_send_headers( req, 200, "application/json", true );
|
|
FILE* f = http_request_get_response_body( req );
|
|
|
|
#include "src/view/api/frontend_config.json.inc"
|
|
|
|
return true;
|
|
}
|
|
|
|
// Route: /api/pleroma
|
|
bool route_pleroma_api2( struct http_request* req )
|
|
{
|
|
if( http_request_route( req, "/frontend_configurations" ) ) {
|
|
return handle_frontend_configurations(req);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Route: /api/v1/pleroma
|
|
bool route_pleroma_api( struct http_request* req )
|
|
{
|
|
printf( "route: route_pleroma_api\n" );
|
|
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 ) {
|
|
printf( "Status %d not found\n", id );
|
|
return false;
|
|
}
|
|
bool result = route_status( req, s );
|
|
status_free(s);
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|