comparison page-search.c @ 78:9bfe5ce3cc45

pasterd: rework themes
author David Demelier <markand@malikania.fr>
date Thu, 16 Mar 2023 20:45:59 +0100
parents fe78b16c694d
children 52029a52a385
comparison
equal deleted inserted replaced
77:fe78b16c694d 78:9bfe5ce3cc45
22 #include "database.h" 22 #include "database.h"
23 #include "json-util.h" 23 #include "json-util.h"
24 #include "page-index.h" 24 #include "page-index.h"
25 #include "page-search.h" 25 #include "page-search.h"
26 #include "page.h" 26 #include "page.h"
27 #include "paste.h"
28 #include "util.h" 27 #include "util.h"
29 28
30 #include "html/search.h" 29 #include "html/search.h"
31 30
32 static inline json_t * 31 #define TITLE "paster -- search"
33 create_root(void) 32 #define LIMIT 16
34 {
35 return json_pack("{ss so}",
36 "pagetitle", "paster -- search",
37 "languages", ju_languages(NULL)
38 );
39 }
40 33
41 static void 34 static void
42 get(struct kreq *req) 35 get(struct kreq *req)
43 { 36 {
44 page(req, KHTTP_200, html_search, create_root()); 37 page(req, KHTTP_200, html_search, json_pack("{ss so}",
38 "pagetitle", "paster -- search",
39 "languages", ju_languages(NULL)
40 ));
45 } 41 }
46 42
47 static void 43 static void
48 post(struct kreq *req) 44 post(struct kreq *req)
49 { 45 {
50 struct paste pastes[10] = {0}; 46 json_t *pastes;
51 size_t pastesz = NELEM(pastes);
52 const char *key, *val, *title = NULL, *author = NULL, *language = NULL; 47 const char *key, *val, *title = NULL, *author = NULL, *language = NULL;
53 48
54 for (size_t i = 0; i < req->fieldsz; ++i) { 49 for (size_t i = 0; i < req->fieldsz; ++i) {
55 key = req->fields[i].key; 50 key = req->fields[i].key;
56 val = req->fields[i].val; 51 val = req->fields[i].val;
67 if (title && strlen(title) == 0) 62 if (title && strlen(title) == 0)
68 title = NULL; 63 title = NULL;
69 if (author && strlen(author) == 0) 64 if (author && strlen(author) == 0)
70 author = NULL; 65 author = NULL;
71 66
72 if (!database_search(pastes, &pastesz, title, author, language)) 67 if (!(pastes = database_search(16, title, author, language)))
73 page_status(req, KHTTP_500); 68 page_status(req, KHTTP_500);
74 else 69 else
75 page_index_render(req, pastes, pastesz); 70 page_index_render(req, pastes);
76
77 for (size_t i = 0; i < pastesz; ++i)
78 paste_finish(&pastes[i]);
79 } 71 }
80 72
81 void 73 void
82 page_search(struct kreq *req) 74 page_search(struct kreq *req)
83 { 75 {