Mercurial > paster
comparison page-paste.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 |
---|---|
20 | 20 |
21 #include "database.h" | 21 #include "database.h" |
22 #include "json-util.h" | 22 #include "json-util.h" |
23 #include "page-paste.h" | 23 #include "page-paste.h" |
24 #include "page.h" | 24 #include "page.h" |
25 #include "paste.h" | |
26 #include "util.h" | 25 #include "util.h" |
27 | 26 |
28 #include "html/paste.h" | 27 #include "html/paste.h" |
29 | 28 |
30 static inline json_t * | 29 static inline json_t * |
31 create_pagetitle(const struct paste *paste) | 30 mk_pagetitle(const json_t *paste) |
32 { | 31 { |
33 return json_sprintf("paster -- %s", paste->title); | 32 return json_sprintf("paster -- %s", ju_get_string(paste, "title")); |
34 } | 33 } |
35 | 34 |
36 static inline json_t * | 35 static inline json_t * |
37 create_paste(const struct paste *paste) | 36 mk_date(const json_t *paste) |
38 { | 37 { |
39 return json_pack("{so ss ss ss ss ss ss so so}", | 38 return ju_date(ju_get_int(paste, "timestamp")); |
40 "pagetitle", create_pagetitle(paste), | 39 } |
41 "id", paste->id, | 40 |
42 "title", paste->title, | 41 static inline json_t * |
43 "author", paste->author, | 42 mk_public(const json_t *paste) |
44 "language", paste->language, | 43 { |
45 "code", paste->code, | 44 const intmax_t visible = ju_get_int(paste, "visible"); |
46 "public", paste->visible ? "Yes" : "No", | 45 |
47 "date", ju_date(paste), | 46 return json_string(visible ? "Yes" : "No"); |
48 "expiration", ju_expiration(paste) | 47 } |
48 | |
49 static inline json_t * | |
50 mk_expires(const json_t *paste) | |
51 { | |
52 return ju_expires( | |
53 ju_get_int(paste, "timestamp"), | |
54 ju_get_int(paste, "duration") | |
49 ); | 55 ); |
50 } | 56 } |
51 | 57 |
52 static void | 58 static void |
53 get(struct kreq *r) | 59 get(struct kreq *req) |
54 { | 60 { |
55 struct paste paste = {0}; | 61 json_t *paste; |
56 | 62 |
57 if (!database_get(&paste, r->path)) | 63 if (!(paste = database_get(req->path))) |
58 page_status(r, KHTTP_404); | 64 page_status(req, KHTTP_404); |
59 else { | 65 else { |
60 page(r, KHTTP_200, html_paste, create_paste(&paste)); | 66 page(req, KHTTP_200, html_paste, ju_extend(paste, "{so so so so}", |
61 paste_finish(&paste); | 67 "pagetitle", mk_pagetitle(paste), |
68 "date", mk_date(paste), | |
69 "public", mk_public(paste), | |
70 "expires", mk_expires(paste) | |
71 )); | |
62 } | 72 } |
63 } | 73 } |
64 | 74 |
65 void | 75 void |
66 page_paste(struct kreq *req) | 76 page_paste(struct kreq *req) |