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 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 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. --- main.c | 6 ++++++ snac.h | 2 ++ utils.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) (limited to 'utils.c') diff --git a/main.c b/main.c index ddb02a8..f271abc 100644 --- a/main.c +++ b/main.c @@ -59,6 +59,7 @@ int usage(const char *cmd) "verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n" "search {basedir} {uid} {regex} Searches posts by content\n" "export_csv {basedir} {uid} Exports followers, lists, MUTEd and bookmarks to CSV\n" + "export_posts {basedir} {iod} Exports all posts to outbox.json\n" "alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n" "migrate {basedir} {uid} Migrates to the account defined as the alias\n" "import_csv {basedir} {uid} Imports data from CSV files\n" @@ -308,6 +309,11 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(cmd, "export_posts") == 0) { /** **/ + export_posts(&snac); + return 0; + } + if (strcmp(cmd, "import_csv") == 0) { /** **/ import_csv(&snac); return 0; diff --git a/snac.h b/snac.h index 7f109e0..42fce87 100644 --- a/snac.h +++ b/snac.h @@ -434,6 +434,8 @@ void mastoapi_purge(void); void verify_links(snac *user); void export_csv(snac *user); +void export_posts(snac *user); + int migrate_account(snac *user); void import_blocked_accounts_csv(snac *user, const char *fn); 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 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 From 23157768d1b94b0a4147b16e5a4272bbf2de1ad5 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sat, 28 Jun 2025 22:46:38 +0200 Subject: Minor CSS tweak. --- doc/style.css | 1 + utils.c | 1 + 2 files changed, 2 insertions(+) (limited to 'utils.c') diff --git a/doc/style.css b/doc/style.css index 027fc43..5289332 100644 --- a/doc/style.css +++ b/doc/style.css @@ -1,5 +1,6 @@ body { max-width: 48em; margin: auto; line-height: 1.5; padding: 0.8em; word-wrap: break-word; } pre { overflow-x: scroll; } +blockquote { font-style: italic; } .snac-embedded-video, img { max-width: 100% } .snac-origin { font-size: 85% } .snac-score { float: right; font-size: 85% } 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