From ff008cf17716c1b0b4394e9d0b83969e419eb844 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Fri, 12 Jan 2024 15:39:59 -0600 Subject: Clean up hardcoded strings --- README.md | 3 ++- assets/entry_edit.html | 4 ++-- assets/footer.html | 9 +++++++++ assets/header.html | 12 ++++++++++++ assets/index_begin.html | 12 ------------ assets/index_end.html | 9 --------- src/clog.c | 30 ++++++++---------------------- 7 files changed, 33 insertions(+), 46 deletions(-) create mode 100644 assets/footer.html create mode 100644 assets/header.html delete mode 100644 assets/index_begin.html delete mode 100644 assets/index_end.html diff --git a/README.md b/README.md index 82bb8d1..876e5ff 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Use `psql` and load `db/db.sql` for models, 1. ~Only do HTTP stuff at the edge.~ 2. ~`PUT`~/`PATCH`? entries. -3. pagination +3. pagination of index ? 4. ~HTML form for edits~ 5. ~Make

first class markdown citizen~ 6. ~Remove JSON API?~ @@ -50,6 +50,7 @@ Use `psql` and load `db/db.sql` for models, 10. Get rid of `requests` dependency in `tests.py` 11. Fix `PATCH` redirects? 12. Search +13. Add preview functionality to edit form ## But using C in 2024 is dangerous? diff --git a/assets/entry_edit.html b/assets/entry_edit.html index 01e5cd5..9982731 100644 --- a/assets/entry_edit.html +++ b/assets/entry_edit.html @@ -3,7 +3,7 @@
- - + + diff --git a/assets/footer.html b/assets/footer.html new file mode 100644 index 0000000..6131a40 --- /dev/null +++ b/assets/footer.html @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/assets/header.html b/assets/header.html new file mode 100644 index 0000000..0ff3660 --- /dev/null +++ b/assets/header.html @@ -0,0 +1,12 @@ + + + + + + +bunkergate.org + + + + + diff --git a/assets/index_begin.html b/assets/index_begin.html deleted file mode 100644 index 0ff3660..0000000 --- a/assets/index_begin.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - -bunkergate.org - - - - - diff --git a/assets/index_end.html b/assets/index_end.html deleted file mode 100644 index 6131a40..0000000 --- a/assets/index_end.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/clog.c b/src/clog.c index 6f54d0f..5f41ce5 100644 --- a/src/clog.c +++ b/src/clog.c @@ -52,9 +52,6 @@ static const char * const error_msg[] = { [HTTP_STATUS_INTERNAL_ERROR] = "There was an error processing the request.", // 500 }; -// void entry_init(); -// void entry_cleanup(); - void entry_query_init(struct entry_query *eq, const char *id); void entry_query_cleanup(struct entry_query *eq); @@ -71,8 +68,6 @@ int get_entry(struct http_request *req); int edit_entry(struct http_request *req); int update_entry(struct http_request *req); -// int v_example_func(struct http_request *req, char *data); - int sql_select(struct entry_query *eq); int sql_update(const char *id, const char *title, const char *body); // int sql_delete(const char *id); @@ -152,9 +147,9 @@ int http_ok_resp( const char *body = kore_buf_stringify(content, NULL); http_response_header(req, "content-type", "text/html; charset=utf-8"); - kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html); + kore_buf_append(resp_buf, asset_header_html, asset_len_header_html); kore_buf_append(resp_buf, body, strlen(body)); - kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html); + kore_buf_append(resp_buf, asset_footer_html, asset_len_footer_html); http_response(req, status, resp_buf->data, resp_buf->offset); @@ -170,9 +165,9 @@ int http_err_resp( struct kore_buf *resp_buf = kore_buf_alloc(0); http_response_header(req, "content-type", "text/html; charset=utf-8"); - kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html); + kore_buf_append(resp_buf, asset_header_html, asset_len_header_html); kore_buf_appendf(resp_buf, (const char *) asset_error_html, error_msg[status]); - kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html); + kore_buf_append(resp_buf, asset_footer_html, asset_len_footer_html); http_response(req, status, resp_buf->data, resp_buf->offset); @@ -205,29 +200,21 @@ int get_index(struct http_request *req) { } // Write table header. - kore_buf_append( - content, - (const char *) "

clog.bunkergate.org

\r\n\r\n", - 94 - ); + kore_buf_append(content, asset_index_header_html, asset_len_index_header_html); // Iterate over entries and render them. for (row = 0; row < eq.num_entries; row++) { // Append rendered MD entry. kore_buf_appendf( content, - (const char *) "\r\n", + (const char *) asset_index_row_html, eq.entries[row]->id, eq.entries[row]->title, eq.entries[row]->created_at, eq.entries[row]->updated_at ); - } // Write table footer. - kore_buf_append( - content, - (const char *) "
titlecreatedupdated
%s%s%s
\r\n", - 10 - ); + kore_buf_append(content, asset_index_footer_html, asset_len_index_footer_html); + http_ok_resp(req, HTTP_STATUS_OK, content); @@ -403,7 +390,6 @@ int update_entry(struct http_request *req) { } err = sql_update(id, title, body); - // err = KORE_RESULT_ERROR; if (err == KORE_RESULT_ERROR) { kore_log(LOG_ERR, "Error updating entry id %s.", id); http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR); -- cgit v1.2.3