commit 9cb6216
default
·
2023-02-05 16:56:59 +0000 UTC
parent 71a7569
timeline_get_by_md5() reads from the user cachedirs instead of the global object. This way, user defined purging will be easier to implement.
1 files changed,
+23,
-4
M
data.c
M
data.c
+23,
-4
1@@ -155,9 +155,6 @@ int user_open(snac *snac, const char *uid)
2 if ((f = fopen(cfg_file, "r")) != NULL) {
3 xs *cfg_data;
4
5-// if (fileno(f) > 100)
6-// snac_log(snac, xs_fmt("CAUTION: fileno() > 100"));
7-
8 /* read full config file */
9 cfg_data = xs_readall(f);
10 fclose(f);
11@@ -816,7 +813,29 @@ double timeline_mtime(snac *snac)
12 int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
13 /* gets a message from the timeline */
14 {
15- return object_get_by_md5(md5, msg);
16+ int status = 404;
17+ FILE *f = NULL;
18+
19+ /* try to open from the private cache first */
20+ xs *prfn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
21+
22+ if ((f = fopen(prfn, "r")) == NULL) {
23+ /* try now the public one */
24+ xs *pufn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
25+ f = fopen(pufn, "r");
26+ }
27+
28+ if (f != NULL) {
29+ flock(fileno(f), LOCK_SH);
30+
31+ xs *j = xs_readall(f);
32+ fclose(f);
33+
34+ if ((*msg = xs_json_loads(j)) != NULL)
35+ status = 200;
36+ }
37+
38+ return status;
39 }
40
41