aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2023-07-07 00:15:09 -0500
committerMichael McVady <femtonaut@gmail.com>2023-07-07 00:15:09 -0500
commitb5c64ec289fe9e07603b3da5f3d246bf88c8a124 (patch)
treec1d5bbd690beb4e3de019c05bbea54dd565853c2 /src
parent01da70c10dd338f1dc6aa319051ce281c73b1528 (diff)
Hack in markdown form
Diffstat (limited to 'src')
-rw-r--r--src/clog.c79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/clog.c b/src/clog.c
index e3a96b0..fd784d2 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -74,6 +74,11 @@ int post_posts(struct http_request *req);
int put_posts(struct http_request *req);
int delete_posts(struct http_request *req);
+int v_example_func(struct http_request *req, char *data);
+
+int get_form(struct http_request *req);
+int post_form(struct http_request *req);
+
int sql_select_posts(struct post_query *pq);
int sql_update_posts(const char *id, const char *title, const char *body);
int sql_delete_posts(const char *id);
@@ -225,6 +230,78 @@ int redirect(struct http_request *req) {
return KORE_RESULT_OK;
}
+int v_example_func(struct http_request *req, char *data) {
+ kore_log(LOG_NOTICE, "v_example_func called");
+ return KORE_RESULT_OK;
+}
+
+int get_form(struct http_request *req) {
+ struct kore_buf *resp_buf = kore_buf_alloc(0);
+
+ kore_buf_append(
+ resp_buf,
+ (const char *) asset_post_edit_html,
+ asset_len_post_edit_html
+ );
+
+ http_ok_resp(req, HTML, HTTP_STATUS_OK, resp_buf);
+
+ kore_buf_free(resp_buf);
+
+ return KORE_RESULT_OK;
+}
+
+
+int post_form(struct http_request *req) {
+
+ struct kore_buf *html_buf = kore_buf_alloc(0);
+ struct kore_buf *resp_buf = kore_buf_alloc(0);
+
+ char *id = NULL;
+ char *title = NULL;
+ char *body = NULL;
+
+ http_populate_multipart_form(req);
+ // http_populate_post(req);
+
+ if (http_argument_get_string(req, "id", &id)) {
+ kore_log(LOG_INFO, "form id %s.", id);
+ }
+
+ if (http_argument_get_string(req, "title", &title)) {
+ kore_log(LOG_INFO, "form title %s.", title);
+ }
+
+ if (http_argument_get_string(req, "body", &body)) {
+ kore_log(LOG_INFO, "form body %s.", body);
+ }
+
+ // Render MD.
+ (void) render_md(body, html_buf);
+ // if (err == KORE_RESULT_ERROR) {
+ // kore_log(LOG_ERR, "Error rendering markdown for post %s.", id);
+ // continue;
+ // }
+
+ // Append rendered MD post.
+ kore_buf_appendf(
+ resp_buf,
+ (const char *) asset_post_html,
+ id,
+ title,
+ "1981-12-23 06:02:00",
+ kore_buf_stringify(html_buf, NULL)
+ );
+
+ http_ok_resp(req, HTML, HTTP_STATUS_OK, resp_buf);
+
+ kore_buf_free(html_buf);
+ kore_buf_free(resp_buf);
+
+ return KORE_RESULT_OK;
+}
+
+
int get_posts(struct http_request *req) {
struct post_query pq;
@@ -380,7 +457,7 @@ int put_posts(struct http_request *req) {
if (item != NULL) {
title = item->data.string;
kore_log(LOG_INFO, "title = '%s'\n", title);
- } else {
+ } else {
status = HTTP_STATUS_BAD_REQUEST;
kore_log(LOG_ERR, "Error parsing title: %s\n", kore_json_strerror());
goto out;