Fossil SCM
Added /json/wiki/preview.
Commit
0165fa184e58fa86006628de22b23f150144dc00
Parent
73816973fb79ad2…
1 file changed
+32
+32
| --- src/json_wiki.c | ||
| +++ src/json_wiki.c | ||
| @@ -24,10 +24,11 @@ | ||
| 24 | 24 | #endif |
| 25 | 25 | |
| 26 | 26 | static cson_value * json_wiki_create(); |
| 27 | 27 | static cson_value * json_wiki_get(); |
| 28 | 28 | static cson_value * json_wiki_list(); |
| 29 | +static cson_value * json_wiki_preview(); | |
| 29 | 30 | static cson_value * json_wiki_save(); |
| 30 | 31 | static cson_value * json_wiki_diff(); |
| 31 | 32 | /* |
| 32 | 33 | ** Mapping of /json/wiki/XXX commands/paths to callbacks. |
| 33 | 34 | */ |
| @@ -34,10 +35,11 @@ | ||
| 34 | 35 | static const JsonPageDef JsonPageDefs_Wiki[] = { |
| 35 | 36 | {"create", json_wiki_create, 0}, |
| 36 | 37 | {"diff", json_wiki_diff, 0}, |
| 37 | 38 | {"get", json_wiki_get, 0}, |
| 38 | 39 | {"list", json_wiki_list, 0}, |
| 40 | +{"preview", json_wiki_preview, 0}, | |
| 39 | 41 | {"save", json_wiki_save, 0}, |
| 40 | 42 | {"timeline", json_timeline_wiki,0}, |
| 41 | 43 | /* Last entry MUST have a NULL name. */ |
| 42 | 44 | {NULL,NULL,0} |
| 43 | 45 | }; |
| @@ -261,10 +263,40 @@ | ||
| 261 | 263 | */ |
| 262 | 264 | |
| 263 | 265 | contentFormat = json_wiki_get_content_format_flag(contentFormat); |
| 264 | 266 | return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat ); |
| 265 | 267 | } |
| 268 | + | |
| 269 | +/* | |
| 270 | +** Implementation of /json/wiki/preview. | |
| 271 | +** | |
| 272 | +*/ | |
| 273 | +static cson_value * json_wiki_preview(){ | |
| 274 | + char const * zPageName; | |
| 275 | + char const * zContent = NULL; | |
| 276 | + cson_value * pay = NULL; | |
| 277 | + Blob contentOrig = empty_blob; | |
| 278 | + Blob contentHtml = empty_blob; | |
| 279 | + if( !g.perm.WrWiki ){ | |
| 280 | + json_set_err(FSL_JSON_E_DENIED, | |
| 281 | + "Requires 'k' access."); | |
| 282 | + return NULL; | |
| 283 | + } | |
| 284 | + zContent = cson_string_cstr(cson_value_get_string(g.json.reqPayload.v)); | |
| 285 | + if(!zContent) { | |
| 286 | + json_set_err(FSL_JSON_E_MISSING_ARGS, | |
| 287 | + "The 'payload' property must be a string containing the wiki code to preview."); | |
| 288 | + return NULL; | |
| 289 | + } | |
| 290 | + blob_append( &contentOrig, zContent, (int)cson_string_length_bytes(cson_value_get_string(g.json.reqPayload.v)) ); | |
| 291 | + wiki_convert( &contentOrig, &contentHtml, 0 ); | |
| 292 | + blob_reset( &contentOrig ); | |
| 293 | + pay = cson_value_new_string( blob_str(&contentHtml), (unsigned int)blob_size(&contentHtml)); | |
| 294 | + blob_reset( &contentHtml ); | |
| 295 | + return pay; | |
| 296 | +} | |
| 297 | + | |
| 266 | 298 | |
| 267 | 299 | /* |
| 268 | 300 | ** Internal impl of /wiki/save and /wiki/create. If createMode is 0 |
| 269 | 301 | ** and the page already exists then a |
| 270 | 302 | ** FSL_JSON_E_RESOURCE_ALREADY_EXISTS error is triggered. If |
| 271 | 303 |
| --- src/json_wiki.c | |
| +++ src/json_wiki.c | |
| @@ -24,10 +24,11 @@ | |
| 24 | #endif |
| 25 | |
| 26 | static cson_value * json_wiki_create(); |
| 27 | static cson_value * json_wiki_get(); |
| 28 | static cson_value * json_wiki_list(); |
| 29 | static cson_value * json_wiki_save(); |
| 30 | static cson_value * json_wiki_diff(); |
| 31 | /* |
| 32 | ** Mapping of /json/wiki/XXX commands/paths to callbacks. |
| 33 | */ |
| @@ -34,10 +35,11 @@ | |
| 34 | static const JsonPageDef JsonPageDefs_Wiki[] = { |
| 35 | {"create", json_wiki_create, 0}, |
| 36 | {"diff", json_wiki_diff, 0}, |
| 37 | {"get", json_wiki_get, 0}, |
| 38 | {"list", json_wiki_list, 0}, |
| 39 | {"save", json_wiki_save, 0}, |
| 40 | {"timeline", json_timeline_wiki,0}, |
| 41 | /* Last entry MUST have a NULL name. */ |
| 42 | {NULL,NULL,0} |
| 43 | }; |
| @@ -261,10 +263,40 @@ | |
| 261 | */ |
| 262 | |
| 263 | contentFormat = json_wiki_get_content_format_flag(contentFormat); |
| 264 | return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat ); |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | ** Internal impl of /wiki/save and /wiki/create. If createMode is 0 |
| 269 | ** and the page already exists then a |
| 270 | ** FSL_JSON_E_RESOURCE_ALREADY_EXISTS error is triggered. If |
| 271 |
| --- src/json_wiki.c | |
| +++ src/json_wiki.c | |
| @@ -24,10 +24,11 @@ | |
| 24 | #endif |
| 25 | |
| 26 | static cson_value * json_wiki_create(); |
| 27 | static cson_value * json_wiki_get(); |
| 28 | static cson_value * json_wiki_list(); |
| 29 | static cson_value * json_wiki_preview(); |
| 30 | static cson_value * json_wiki_save(); |
| 31 | static cson_value * json_wiki_diff(); |
| 32 | /* |
| 33 | ** Mapping of /json/wiki/XXX commands/paths to callbacks. |
| 34 | */ |
| @@ -34,10 +35,11 @@ | |
| 35 | static const JsonPageDef JsonPageDefs_Wiki[] = { |
| 36 | {"create", json_wiki_create, 0}, |
| 37 | {"diff", json_wiki_diff, 0}, |
| 38 | {"get", json_wiki_get, 0}, |
| 39 | {"list", json_wiki_list, 0}, |
| 40 | {"preview", json_wiki_preview, 0}, |
| 41 | {"save", json_wiki_save, 0}, |
| 42 | {"timeline", json_timeline_wiki,0}, |
| 43 | /* Last entry MUST have a NULL name. */ |
| 44 | {NULL,NULL,0} |
| 45 | }; |
| @@ -261,10 +263,40 @@ | |
| 263 | */ |
| 264 | |
| 265 | contentFormat = json_wiki_get_content_format_flag(contentFormat); |
| 266 | return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat ); |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | ** Implementation of /json/wiki/preview. |
| 271 | ** |
| 272 | */ |
| 273 | static cson_value * json_wiki_preview(){ |
| 274 | char const * zPageName; |
| 275 | char const * zContent = NULL; |
| 276 | cson_value * pay = NULL; |
| 277 | Blob contentOrig = empty_blob; |
| 278 | Blob contentHtml = empty_blob; |
| 279 | if( !g.perm.WrWiki ){ |
| 280 | json_set_err(FSL_JSON_E_DENIED, |
| 281 | "Requires 'k' access."); |
| 282 | return NULL; |
| 283 | } |
| 284 | zContent = cson_string_cstr(cson_value_get_string(g.json.reqPayload.v)); |
| 285 | if(!zContent) { |
| 286 | json_set_err(FSL_JSON_E_MISSING_ARGS, |
| 287 | "The 'payload' property must be a string containing the wiki code to preview."); |
| 288 | return NULL; |
| 289 | } |
| 290 | blob_append( &contentOrig, zContent, (int)cson_string_length_bytes(cson_value_get_string(g.json.reqPayload.v)) ); |
| 291 | wiki_convert( &contentOrig, &contentHtml, 0 ); |
| 292 | blob_reset( &contentOrig ); |
| 293 | pay = cson_value_new_string( blob_str(&contentHtml), (unsigned int)blob_size(&contentHtml)); |
| 294 | blob_reset( &contentHtml ); |
| 295 | return pay; |
| 296 | } |
| 297 | |
| 298 | |
| 299 | /* |
| 300 | ** Internal impl of /wiki/save and /wiki/create. If createMode is 0 |
| 301 | ** and the page already exists then a |
| 302 | ** FSL_JSON_E_RESOURCE_ALREADY_EXISTS error is triggered. If |
| 303 |