summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2023-02-05 17:56:59 +0100
committerGravatar default2023-02-05 17:56:59 +0100
commit9cb621641718a974f5de38696ed36333805f2397 (patch)
treef86b10b59cec1abb8eb73637902f8c35355f28c7 /data.c
parentDeleted the type argument from object_get_my_md5() and object_get(). (diff)
downloadsnac2-9cb621641718a974f5de38696ed36333805f2397.tar.gz
snac2-9cb621641718a974f5de38696ed36333805f2397.tar.xz
snac2-9cb621641718a974f5de38696ed36333805f2397.zip
timeline_get_by_md5() reads from the user cachedirs instead of the global object.
This way, user defined purging will be easier to implement.
Diffstat (limited to 'data.c')
-rw-r--r--data.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/data.c b/data.c
index 6c3408f..5d4e73c 100644
--- a/data.c
+++ b/data.c
@@ -155,9 +155,6 @@ int user_open(snac *snac, const char *uid)
155 if ((f = fopen(cfg_file, "r")) != NULL) { 155 if ((f = fopen(cfg_file, "r")) != NULL) {
156 xs *cfg_data; 156 xs *cfg_data;
157 157
158// if (fileno(f) > 100)
159// snac_log(snac, xs_fmt("CAUTION: fileno() > 100"));
160
161 /* read full config file */ 158 /* read full config file */
162 cfg_data = xs_readall(f); 159 cfg_data = xs_readall(f);
163 fclose(f); 160 fclose(f);
@@ -816,7 +813,29 @@ double timeline_mtime(snac *snac)
816int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) 813int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
817/* gets a message from the timeline */ 814/* gets a message from the timeline */
818{ 815{
819 return object_get_by_md5(md5, msg); 816 int status = 404;
817 FILE *f = NULL;
818
819 /* try to open from the private cache first */
820 xs *prfn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
821
822 if ((f = fopen(prfn, "r")) == NULL) {
823 /* try now the public one */
824 xs *pufn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
825 f = fopen(pufn, "r");
826 }
827
828 if (f != NULL) {
829 flock(fileno(f), LOCK_SH);
830
831 xs *j = xs_readall(f);
832 fclose(f);
833
834 if ((*msg = xs_json_loads(j)) != NULL)
835 status = 200;
836 }
837
838 return status;
820} 839}
821 840
822 841