From d5dbdad930d44d9345bec03d0f2ce4076cb028a8 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sat, 7 Jun 2025 07:53:00 +0200 Subject: If a metadata value is an account handle, it's also verified using webfinger. --- utils.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index d50707a..d8c55dc 100644 --- a/utils.c +++ b/utils.c @@ -488,6 +488,18 @@ void verify_links(snac *user) int c = 0; while (metadata && xs_dict_next(metadata, &k, &v, &c)) { + xs *wfinger = NULL; + const char *ov = NULL; + + /* is it an account handle? */ + if (*v == '@' && strchr(v + 1, '@')) { + /* resolve it via webfinger */ + if (valid_status(webfinger_request(v, &wfinger, NULL)) && xs_is_string(wfinger)) { + ov = v; + v = wfinger; + } + } + /* not an https link? skip */ if (!xs_startswith(v, "https:/" "/")) continue; @@ -563,6 +575,10 @@ void verify_links(snac *user) user->links = xs_dict_set(user->links, v, verified_time); + /* also add the original value if it was 'resolved' */ + if (xs_is_string(ov)) + user->links = xs_dict_set(user->links, ov, v); + vfied = 1; } else -- cgit v1.2.3 From dfd246a0e9df31f315f1fd650c9b916195b2c9e4 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sat, 7 Jun 2025 08:19:40 +0200 Subject: Always store resolved account handles as metadata, even if they weren't verified. --- utils.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'utils.c') diff --git a/utils.c b/utils.c index d8c55dc..7adbce2 100644 --- a/utils.c +++ b/utils.c @@ -497,6 +497,14 @@ void verify_links(snac *user) if (valid_status(webfinger_request(v, &wfinger, NULL)) && xs_is_string(wfinger)) { ov = v; v = wfinger; + + /* store the alias */ + if (user->links == NULL) + user->links = xs_dict_new(); + + user->links = xs_dict_set(user->links, ov, v); + + changed++; } } @@ -575,10 +583,6 @@ void verify_links(snac *user) user->links = xs_dict_set(user->links, v, verified_time); - /* also add the original value if it was 'resolved' */ - if (xs_is_string(ov)) - user->links = xs_dict_set(user->links, ov, v); - vfied = 1; } else -- cgit v1.2.3 From a07458f408c304ae9d037c95bee77dbf4522f3f0 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 19 Jun 2025 19:19:08 +0200 Subject: New command-line option export_posts. --- utils.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 7adbce2..5367f22 100644 --- a/utils.c +++ b/utils.c @@ -725,6 +725,58 @@ void export_csv(snac *user) } +void export_posts(snac *user) +/* exports all posts to an OrderedCollection */ +{ + xs *ifn = xs_fmt("%s/public.idx", user->basedir); + xs *index = index_list(ifn, XS_ALL); + xs *ofn = xs_fmt("%s/export/outbox.json", user->basedir); + FILE *f; + + if ((f = fopen(ofn, "w")) == NULL) { + snac_log(user, xs_fmt("Cannot create file %s", ofn)); + return; + } + + int cnt = 0; + + /* raw output */ + fprintf(f, "{\"@context\": \"https:/" "/www.w3.org/ns/activitystreams\","); + fprintf(f, "\"id\": \"outbox.json\","); + fprintf(f, "\"type\": \"OrderedCollection\","); + fprintf(f, "\"orderedItems\": ["); + + const char *md5; + + snac_log(user, xs_fmt("Creating %s...", ofn)); + + xs_list_foreach(index, md5) { + xs *obj = NULL; + + if (!valid_status(object_get_by_md5(md5, &obj))) + continue; + + const char *type = xs_dict_get(obj, "type"); + + if (!xs_is_string(type) || strcmp(type, "Note")) + continue; + + const char *atto = get_atto(obj); + + if (!xs_is_string(atto) || strcmp(atto, user->actor)) + continue; + + xs *c_msg = msg_create(user, obj); + xs_json_dump(c_msg, 0, f); + cnt++; + } + + fprintf(f, "], \"totalItems\": %d}", cnt); + + fclose(f); +} + + void import_blocked_accounts_csv(snac *user, const char *ifn) /* imports a Mastodon CSV file of blocked accounts */ { -- cgit v1.2.3 From 8fdfb5b70d638b0f3c426c8a3ea7d2c2c0937a05 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 19 Jun 2025 19:31:42 +0200 Subject: Fixed bug in export_posts(). --- utils.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 5367f22..f0307cc 100644 --- a/utils.c +++ b/utils.c @@ -766,6 +766,9 @@ void export_posts(snac *user) if (!xs_is_string(atto) || strcmp(atto, user->actor)) continue; + if (cnt) + fprintf(f, ","); + xs *c_msg = msg_create(user, obj); xs_json_dump(c_msg, 0, f); cnt++; -- cgit v1.2.3 From 23157768d1b94b0a4147b16e5a4272bbf2de1ad5 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sat, 28 Jun 2025 22:46:38 +0200 Subject: Minor CSS tweak. --- utils.c | 1 + 1 file changed, 1 insertion(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index f0307cc..8db20bd 100644 --- a/utils.c +++ b/utils.c @@ -45,6 +45,7 @@ static const char *default_srv_config = "{" static const char *default_css = "body { max-width: 48em; margin: auto; line-height: 1.5; padding: 0.8em; word-wrap: break-word; }\n" "pre { overflow-x: scroll; }\n" + "blockquote { font-style: italic; }\n" ".snac-embedded-video, img { max-width: 100% }\n" ".snac-origin { font-size: 85% }\n" ".snac-score { float: right; font-size: 85% }\n" -- cgit v1.2.3