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.
67 lines
1.5 KiB
C
67 lines
1.5 KiB
C
#include "Attachement.h"
|
|
|
|
#include "json/json.h"
|
|
#include "json/layout.h"
|
|
#include "util/format.h"
|
|
|
|
#include "model/server.h"
|
|
#include "model/media.h"
|
|
|
|
bool int_to_string_callback( void* field_data, bool is_read, char** res );
|
|
bool preview_url_string_callback( void* field_data, bool is_read, char** res )
|
|
{
|
|
struct media* m = field_data;
|
|
if( !is_read ) {
|
|
*res = aformat( "https://%s/media/%d/preview", g_server->domain, m->id );
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
bool url_string_callback( void* field_data, bool is_read, char** res )
|
|
{
|
|
struct media* m = field_data;
|
|
if( !is_read ) {
|
|
*res = aformat( "https://%s/media/%d/blob", g_server->domain, m->id );
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
#define OBJ_TYPE struct media
|
|
static struct json_object_field api_Attachment_layout[] = {
|
|
{
|
|
.key = "id",
|
|
.offset = offsetof( OBJ_TYPE, id ),
|
|
.type = &json_field_callback_string,
|
|
.string_callback = int_to_string_callback,
|
|
},
|
|
JSON_FIELD_FIXED_STRING( type, "image", true ),
|
|
{
|
|
.key = "preview_url",
|
|
.offset = 0,
|
|
.required = true,
|
|
.type = &json_field_callback_string,
|
|
.string_callback = preview_url_string_callback,
|
|
},
|
|
{
|
|
.key = "url",
|
|
.offset = 0,
|
|
.required = true,
|
|
.type = &json_field_callback_string,
|
|
.string_callback = url_string_callback,
|
|
},
|
|
JSON_FIELD_END,
|
|
};
|
|
#undef OBJ_TYPE
|
|
|
|
void api_Attachement_write( struct media* m, FILE* f, int indent )
|
|
{
|
|
struct json_writer jw = {
|
|
.f = f,
|
|
.indentation = "\t",
|
|
.indent = indent,
|
|
};
|
|
|
|
json_write_pretty_object_layout( &jw, api_Attachment_layout, m );
|
|
}
|
|
|