Upgraded local/ to public/.

This commit is contained in:
default 2022-12-03 17:58:49 +01:00
parent af6d31ff83
commit d00026ac06
4 changed files with 79 additions and 4 deletions

10
data.c
View file

@ -15,7 +15,7 @@
#include <sys/file.h> #include <sys/file.h>
#include <fcntl.h> #include <fcntl.h>
double db_layout = 2.5; double db_layout = 2.6;
int db_upgrade(d_char **error); int db_upgrade(d_char **error);
@ -500,9 +500,13 @@ int _object_add(const char *id, d_char *obj, int ow)
xs *c_idx = _object_fn(in_reply_to); xs *c_idx = _object_fn(in_reply_to);
c_idx = xs_replace_i(c_idx, ".json", "_c.idx"); c_idx = xs_replace_i(c_idx, ".json", "_c.idx");
index_add(c_idx, id);
srv_debug(0, xs_fmt("object_add added child %s to %s", id, c_idx)); if (!index_in(c_idx, id)) {
index_add(c_idx, id);
srv_debug(0, xs_fmt("object_add added child %s to %s", id, c_idx));
}
else
srv_debug(0, xs_fmt("object_add %s child already in %s", id, c_idx));
/* create a one-element index with the parent */ /* create a one-element index with the parent */
xs *p_idx = xs_replace(fn, ".json", "_p.idx"); xs *p_idx = xs_replace(fn, ".json", "_p.idx");

8
html.c
View file

@ -594,7 +594,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int
/* is the parent not here? */ /* is the parent not here? */
char *parent = xs_dict_get(msg, "inReplyTo"); char *parent = xs_dict_get(msg, "inReplyTo");
if (!xs_is_null(parent) && !object_here(parent)) { if (!xs_is_null(parent) && *parent && !object_here(parent)) {
xs *s1 = xs_fmt( xs *s1 = xs_fmt(
"<div class=\"snac-origin\">%s " "<div class=\"snac-origin\">%s "
"<a href=\"%s\">»</a></div>\n", "<a href=\"%s\">»</a></div>\n",
@ -624,6 +624,12 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int
sensitive = 1; sensitive = 1;
} }
{
xs *md5 = xs_md5_hex(id, strlen(id));
xs *s1 = xs_fmt("<p><code>%s</code></p>\n", md5);
s = xs_str_cat(s, s1);
}
{ {
xs *c = sanitize(xs_dict_get(msg, "content")); xs *c = sanitize(xs_dict_get(msg, "content"));
char *p, *v; char *p, *v;

6
snac.h
View file

@ -60,18 +60,24 @@ int index_first(const char *fn, char *buf, int size);
d_char *index_list(const char *fn, int max); d_char *index_list(const char *fn, int max);
d_char *index_list_desc(const char *fn, int max); d_char *index_list_desc(const char *fn, int max);
int object_add(const char *id, d_char *obj);
int object_add_ow(const char *id, d_char *obj);
int object_here_by_md5(char *id); int object_here_by_md5(char *id);
int object_here(char *id); int object_here(char *id);
int object_get_by_md5(const char *md5, d_char **obj, const char *type); int object_get_by_md5(const char *md5, d_char **obj, const char *type);
int object_get(const char *id, d_char **obj, const char *type); int object_get(const char *id, d_char **obj, const char *type);
int object_del(const char *id); int object_del(const char *id);
int object_del_if_unref(const char *id); int object_del_if_unref(const char *id);
int object_admire(const char *id, const char *actor, int like);
d_char *object_children(const char *id); d_char *object_children(const char *id);
d_char *object_likes(const char *id); d_char *object_likes(const char *id);
d_char *object_announces(const char *id); d_char *object_announces(const char *id);
int object_parent(const char *id, char *buf, int size); int object_parent(const char *id, char *buf, int size);
int object_user_cache_add(snac *snac, const char *id, const char *cachedir);
int object_user_cache_del(snac *snac, const char *id, const char *cachedir);
int follower_add(snac *snac, const char *actor); int follower_add(snac *snac, const char *actor);
int follower_del(snac *snac, const char *actor); int follower_del(snac *snac, const char *actor);
int follower_check(snac *snac, const char *actor); int follower_check(snac *snac, const char *actor);

View file

@ -171,6 +171,65 @@ int db_upgrade(d_char **error)
nf = 2.5; nf = 2.5;
} }
else
if (f < 2.6) {
/* upgrade local/ to public/ */
xs *users = user_list();
char *p, *v;
p = users;
while (xs_list_iter(&p, &v)) {
snac snac;
if (user_open(&snac, v)) {
xs *spec = xs_fmt("%s/local/" "*.json", snac.basedir);
xs *dir = xs_glob(spec, 0, 0);
char *p, *v;
p = dir;
while (xs_list_iter(&p, &v)) {
FILE *f;
if ((f = fopen(v, "r")) != NULL) {
xs *s = xs_readall(f);
xs *o = xs_json_loads(s);
fclose(f);
xs *meta = xs_dup(xs_dict_get(o, "_snac"));
o = xs_dict_del(o, "_snac");
char *id = xs_dict_get(o, "id");
/* store object */
object_add_ow(id, o);
/* if it's from us, add to public */
if (xs_startswith(id, snac.actor)) {
char *p, *v;
object_user_cache_add(&snac, id, "public");
p = xs_dict_get(meta, "announced_by");
while (xs_list_iter(&p, &v))
object_admire(id, v, 0);
p = xs_dict_get(meta, "liked_by");
while (xs_list_iter(&p, &v))
object_admire(id, v, 1);
}
unlink(v);
}
}
xs *od = xs_fmt("%s/local", snac.basedir);
rmdir(od);
user_free(&snac);
}
}
nf = 2.6;
}
if (f < nf) { if (f < nf) {
f = nf; f = nf;