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.
72 lines
1.6 KiB
C
72 lines
1.6 KiB
C
#include "emoji.h"
|
|
|
|
#include "http/server/request.h"
|
|
#include "util/format.h"
|
|
|
|
#include "model/server.h"
|
|
#include "model/emoji.h"
|
|
|
|
#include "view/api/Emoji.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
#include <sys/types.h>
|
|
#include <dirent.h>
|
|
|
|
// Route: /api/v1/custom_emojis
|
|
bool route_custom_emojis( struct http_request* req )
|
|
{
|
|
http_request_send_headers( req, 200, "application/json", true );
|
|
FILE* f = http_request_get_response_body( req );
|
|
fprintf( f, "[" );
|
|
DIR* d = opendir( "data/emoji" );
|
|
struct dirent* ent;
|
|
bool first = true;
|
|
while(( ent = readdir(d) )) {
|
|
if( ent->d_name[0] != '.' && !index(ent->d_name,' ') ) {
|
|
if( !first ) {
|
|
fprintf( f, "," );
|
|
} else {
|
|
fprintf( f, "\n" );
|
|
}
|
|
char* filename = strdup(ent->d_name);
|
|
char* remain = NULL;
|
|
char* shortcode = strtok_r(filename, ".", &remain );
|
|
|
|
struct emoji* e = emoji_from_shortcode( shortcode );
|
|
api_Emoji_write( e, f, 1 );
|
|
emoji_free(e);
|
|
free(filename);
|
|
|
|
first = false;
|
|
}
|
|
}
|
|
closedir(d);
|
|
|
|
fprintf( f, "\n]" );
|
|
|
|
return true;
|
|
}
|
|
|
|
const char* mime_type_for_filename( const char* filename );
|
|
|
|
bool route_emoji_asset( struct http_request* req )
|
|
{
|
|
char* id_str = http_request_route_get_dir_or_file(req);
|
|
char* filename = filename_for_shortcode( id_str );
|
|
free(id_str);
|
|
|
|
if( !filename ) { return false; }
|
|
|
|
const char* mime_type = mime_type_for_filename( filename );
|
|
char fs_path[512];
|
|
snprintf( fs_path, 512, "data/emoji/%s", filename );
|
|
free(filename);
|
|
|
|
return http_request_send_file( req, fs_path, mime_type );
|
|
}
|
|
|