diff 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
line wrap: on
line diff
--- a/page-search.c	Thu Mar 16 15:05:26 2023 +0100
+++ b/page-search.c	Thu Mar 16 20:45:59 2023 +0100
@@ -24,31 +24,26 @@
 #include "page-index.h"
 #include "page-search.h"
 #include "page.h"
-#include "paste.h"
 #include "util.h"
 
 #include "html/search.h"
 
-static inline json_t *
-create_root(void)
-{
-	return json_pack("{ss so}",
-		"pagetitle",    "paster -- search",
-		"languages",    ju_languages(NULL)
-	);
-}
+#define TITLE    "paster -- search"
+#define LIMIT    16
 
 static void
 get(struct kreq *req)
 {
-	page(req, KHTTP_200, html_search, create_root());
+	page(req, KHTTP_200, html_search, json_pack("{ss so}",
+		"pagetitle",    "paster -- search",
+		"languages",    ju_languages(NULL)
+	));
 }
 
 static void
 post(struct kreq *req)
 {
-	struct paste pastes[10] = {0};
-	size_t pastesz = NELEM(pastes);
+	json_t *pastes;
 	const char *key, *val, *title = NULL, *author = NULL, *language = NULL;
 
 	for (size_t i = 0; i < req->fieldsz; ++i) {
@@ -69,13 +64,10 @@
 	if (author && strlen(author) == 0)
 		author = NULL;
 
-	if (!database_search(pastes, &pastesz, title, author, language))
+	if (!(pastes = database_search(16, title, author, language)))
 		page_status(req, KHTTP_500);
 	else
-		page_index_render(req, pastes, pastesz);
-
-	for (size_t i = 0; i < pastesz; ++i)
-		paste_finish(&pastes[i]);
+		page_index_render(req, pastes);
 }
 
 void