Mercurial > paster
comparison page-paste.c @ 77:fe78b16c694d
pasterd: refactor json utilities
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 16 Mar 2023 15:05:26 +0100 |
parents | b12491ceabfd |
children | 9bfe5ce3cc45 |
comparison
equal
deleted
inserted
replaced
76:9643962908ab | 77:fe78b16c694d |
---|---|
17 */ | 17 */ |
18 | 18 |
19 #include <assert.h> | 19 #include <assert.h> |
20 | 20 |
21 #include "database.h" | 21 #include "database.h" |
22 #include "paste.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" | |
25 #include "util.h" | 26 #include "util.h" |
26 | 27 |
27 #include "html/paste.h" | 28 #include "html/paste.h" |
28 | |
29 // TODO: share this. | |
30 static inline json_t * | |
31 create_date(const struct paste *paste) | |
32 { | |
33 return json_string(bstrftime("%c", localtime(&paste->timestamp))); | |
34 } | |
35 | |
36 static inline json_t * | |
37 create_expiration(const struct paste *paste) | |
38 { | |
39 return json_string(ttl(paste->timestamp, paste->duration)); | |
40 } | |
41 | 29 |
42 static inline json_t * | 30 static inline json_t * |
43 create_pagetitle(const struct paste *paste) | 31 create_pagetitle(const struct paste *paste) |
44 { | 32 { |
45 return json_sprintf("paster -- %s", paste->title); | 33 return json_sprintf("paster -- %s", paste->title); |
54 "title", paste->title, | 42 "title", paste->title, |
55 "author", paste->author, | 43 "author", paste->author, |
56 "language", paste->language, | 44 "language", paste->language, |
57 "code", paste->code, | 45 "code", paste->code, |
58 "public", paste->visible ? "Yes" : "No", | 46 "public", paste->visible ? "Yes" : "No", |
59 "date", create_date(paste), | 47 "date", ju_date(paste), |
60 "expiration", create_expiration(paste) | 48 "expiration", ju_expiration(paste) |
61 ); | 49 ); |
62 } | 50 } |
63 | 51 |
64 static void | 52 static void |
65 get(struct kreq *r) | 53 get(struct kreq *r) |