parent
e510eeb57b
commit
67b6f6b73f
@ -1 +1 @@
|
||||
Subproject commit a419c6373c59e3e5a2094180213d94924ca41317
|
||||
Subproject commit 45790a0384ac4fb95c07fe3d97669b6b7bc743bc
|
@ -0,0 +1,46 @@
|
||||
#include "Tag.h"
|
||||
|
||||
#include "model/server.h"
|
||||
|
||||
#include "json/json.h"
|
||||
#include "json/layout.h"
|
||||
#include "util/format.h"
|
||||
|
||||
static bool simple_copy_callback( void* field_data, bool is_read, char** val )
|
||||
{
|
||||
if( is_read ) { return false; }
|
||||
|
||||
char* tag = field_data;
|
||||
*val = safe_strdup(tag);
|
||||
return true;
|
||||
};
|
||||
static bool tag_url_callback( void* field_data, bool is_read, char** val )
|
||||
{
|
||||
if( is_read ) { return false; }
|
||||
|
||||
char* tag = field_data;
|
||||
*val = aformat( "https://%s/tag/%s", g_server->domain, tag );
|
||||
return true;
|
||||
};
|
||||
|
||||
static struct json_object_field Tag_layout[] = {
|
||||
{
|
||||
.key = "name",
|
||||
.offset = 0,
|
||||
.type = &json_field_callback_string,
|
||||
.string_callback = simple_copy_callback,
|
||||
},
|
||||
{
|
||||
.key = "url",
|
||||
.offset = 0,
|
||||
.type = &json_field_callback_string,
|
||||
.string_callback = tag_url_callback,
|
||||
},
|
||||
JSON_FIELD_END,
|
||||
};
|
||||
struct json_field_type Tag_type = {
|
||||
.layout = Tag_layout,
|
||||
.reader = json_field_object_type_reader,
|
||||
.writer = json_field_object_type_writer,
|
||||
.size = sizeof(char*),
|
||||
};
|
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
extern struct json_field_type Tag_type;
|
||||
|
Loading…
Reference in new issue