From 55d3ef5024d4a597ddeae23ca7d29375c7d6a9d3 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 8 Nov 2023 09:20:34 +0100 Subject: [PATCH] Tags can now be searched for from the server base URL. --- data.c | 5 ++--- html.c | 2 +- httpd.c | 15 +++++++++++++++ snac.h | 4 +++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/data.c b/data.c index 5026154..cd9c5e7 100644 --- a/data.c +++ b/data.c @@ -1575,7 +1575,6 @@ void tag_index(const char *id, const xs_dict *obj) xs_list *tags = xs_dict_get(obj, "tag"); if (is_msg_public(obj) && xs_type(tags) == XSTYPE_LIST && xs_list_len(tags) > 0) { - xs *md5_id = xs_md5_hex(id, strlen(id)); xs *g_tag_dir = xs_fmt("%s/tag", srv_basedir); mkdirx(g_tag_dir); @@ -1596,7 +1595,7 @@ void tag_index(const char *id, const xs_dict *obj) mkdirx(tag_dir); xs *g_tag_idx = xs_fmt("%s/%s.idx", tag_dir, md5_tag); - index_add(g_tag_idx, md5_id); + index_add(g_tag_idx, id); FILE *f; xs *g_tag_name = xs_replace(g_tag_idx, ".idx", ".tag"); @@ -1605,7 +1604,7 @@ void tag_index(const char *id, const xs_dict *obj) fclose(f); } - srv_debug(0, xs_fmt("tagged %s #%s (%s #%s)", id, name, md5_id, md5_tag)); + srv_debug(0, xs_fmt("tagged %s #%s (#%s)", id, name, md5_tag)); } } } diff --git a/html.c b/html.c index 7e96f46..1220765 100644 --- a/html.c +++ b/html.c @@ -1574,7 +1574,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int continue; /* if it's an instance page, discard private users */ - if (user == NULL) { + if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) { const char *atto = xs_dict_get(msg, "attributedTo"); xs *l = xs_split(atto, "/"); const char *uid = xs_list_get(l, -1); diff --git a/httpd.c b/httpd.c index aed15dc..2a91523 100644 --- a/httpd.c +++ b/httpd.c @@ -141,6 +141,21 @@ int server_get_handler(xs_dict *req, const char *q_path, /* is it the server root? */ if (*q_path == '\0') { + xs_dict *q_vars = xs_dict_get(req, "q_vars"); + char *t = NULL; + + if (xs_type(q_vars) == XSTYPE_DICT && (t = xs_dict_get(q_vars, "t"))) { + /* tag search query */ + int skip = xs_number_get(xs_dict_get(q_vars, "skip")); + int show = xs_number_get(xs_dict_get(q_vars, "show")); + + if (show == 0) + show = 64; + + xs *tl = tag_search(t, skip, show); + *body = html_timeline(NULL, tl, 0, skip, show, 0); + } + else if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) { xs *tl = timeline_instance_list(0, 30); *body = html_timeline(NULL, tl, 0, 0, 0, 0); diff --git a/snac.h b/snac.h index 582f5f1..8c02004 100644 --- a/snac.h +++ b/snac.h @@ -69,7 +69,8 @@ double mtime_nl(const char *fn, int *n_link); #define mtime(fn) mtime_nl(fn, NULL) double f_ctime(const char *fn); -int index_add(const char *fn, const char *md5); +int index_add_md5(const char *fn, const char *md5); +int index_add(const char *fn, const char *id); int index_gc(const char *fn); int index_first(const char *fn, char *buf, int size); int index_len(const char *fn); @@ -144,6 +145,7 @@ void hide(snac *snac, const char *id); int is_hidden(snac *snac, const char *id); void tag_index(const char *id, const xs_dict *obj); +xs_list *tag_search(char *tag, int skip, int show); int actor_add(const char *actor, xs_dict *msg); int actor_get(const char *actor, xs_dict **data);