mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
timeline_get_by_md5() reads from the user cachedirs instead of the global object.
This way, user defined purging will be easier to implement.
This commit is contained in:
parent
71a7569467
commit
9cb6216417
1 changed files with 23 additions and 4 deletions
27
data.c
27
data.c
|
@ -155,9 +155,6 @@ int user_open(snac *snac, const char *uid)
|
|||
if ((f = fopen(cfg_file, "r")) != NULL) {
|
||||
xs *cfg_data;
|
||||
|
||||
// if (fileno(f) > 100)
|
||||
// snac_log(snac, xs_fmt("CAUTION: fileno() > 100"));
|
||||
|
||||
/* read full config file */
|
||||
cfg_data = xs_readall(f);
|
||||
fclose(f);
|
||||
|
@ -816,7 +813,29 @@ double timeline_mtime(snac *snac)
|
|||
int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
|
||||
/* gets a message from the timeline */
|
||||
{
|
||||
return object_get_by_md5(md5, msg);
|
||||
int status = 404;
|
||||
FILE *f = NULL;
|
||||
|
||||
/* try to open from the private cache first */
|
||||
xs *prfn = xs_fmt("%s/private/%s.json", snac->basedir, md5);
|
||||
|
||||
if ((f = fopen(prfn, "r")) == NULL) {
|
||||
/* try now the public one */
|
||||
xs *pufn = xs_fmt("%s/public/%s.json", snac->basedir, md5);
|
||||
f = fopen(pufn, "r");
|
||||
}
|
||||
|
||||
if (f != NULL) {
|
||||
flock(fileno(f), LOCK_SH);
|
||||
|
||||
xs *j = xs_readall(f);
|
||||
fclose(f);
|
||||
|
||||
if ((*msg = xs_json_loads(j)) != NULL)
|
||||
status = 200;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue