summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index d50707a..8db20bd 100644
--- a/utils.c
+++ b/utils.c
@@ -45,6 +45,7 @@ static const char *default_srv_config = "{"
45static const char *default_css = 45static const char *default_css =
46 "body { max-width: 48em; margin: auto; line-height: 1.5; padding: 0.8em; word-wrap: break-word; }\n" 46 "body { max-width: 48em; margin: auto; line-height: 1.5; padding: 0.8em; word-wrap: break-word; }\n"
47 "pre { overflow-x: scroll; }\n" 47 "pre { overflow-x: scroll; }\n"
48 "blockquote { font-style: italic; }\n"
48 ".snac-embedded-video, img { max-width: 100% }\n" 49 ".snac-embedded-video, img { max-width: 100% }\n"
49 ".snac-origin { font-size: 85% }\n" 50 ".snac-origin { font-size: 85% }\n"
50 ".snac-score { float: right; font-size: 85% }\n" 51 ".snac-score { float: right; font-size: 85% }\n"
@@ -488,6 +489,26 @@ void verify_links(snac *user)
488 489
489 int c = 0; 490 int c = 0;
490 while (metadata && xs_dict_next(metadata, &k, &v, &c)) { 491 while (metadata && xs_dict_next(metadata, &k, &v, &c)) {
492 xs *wfinger = NULL;
493 const char *ov = NULL;
494
495 /* is it an account handle? */
496 if (*v == '@' && strchr(v + 1, '@')) {
497 /* resolve it via webfinger */
498 if (valid_status(webfinger_request(v, &wfinger, NULL)) && xs_is_string(wfinger)) {
499 ov = v;
500 v = wfinger;
501
502 /* store the alias */
503 if (user->links == NULL)
504 user->links = xs_dict_new();
505
506 user->links = xs_dict_set(user->links, ov, v);
507
508 changed++;
509 }
510 }
511
491 /* not an https link? skip */ 512 /* not an https link? skip */
492 if (!xs_startswith(v, "https:/" "/")) 513 if (!xs_startswith(v, "https:/" "/"))
493 continue; 514 continue;
@@ -705,6 +726,61 @@ void export_csv(snac *user)
705} 726}
706 727
707 728
729void export_posts(snac *user)
730/* exports all posts to an OrderedCollection */
731{
732 xs *ifn = xs_fmt("%s/public.idx", user->basedir);
733 xs *index = index_list(ifn, XS_ALL);
734 xs *ofn = xs_fmt("%s/export/outbox.json", user->basedir);
735 FILE *f;
736
737 if ((f = fopen(ofn, "w")) == NULL) {
738 snac_log(user, xs_fmt("Cannot create file %s", ofn));
739 return;
740 }
741
742 int cnt = 0;
743
744 /* raw output */
745 fprintf(f, "{\"@context\": \"https:/" "/www.w3.org/ns/activitystreams\",");
746 fprintf(f, "\"id\": \"outbox.json\",");
747 fprintf(f, "\"type\": \"OrderedCollection\",");
748 fprintf(f, "\"orderedItems\": [");
749
750 const char *md5;
751
752 snac_log(user, xs_fmt("Creating %s...", ofn));
753
754 xs_list_foreach(index, md5) {
755 xs *obj = NULL;
756
757 if (!valid_status(object_get_by_md5(md5, &obj)))
758 continue;
759
760 const char *type = xs_dict_get(obj, "type");
761
762 if (!xs_is_string(type) || strcmp(type, "Note"))
763 continue;
764
765 const char *atto = get_atto(obj);
766
767 if (!xs_is_string(atto) || strcmp(atto, user->actor))
768 continue;
769
770 if (cnt)
771 fprintf(f, ",");
772
773 xs *c_msg = msg_create(user, obj);
774 xs_json_dump(c_msg, 0, f);
775 cnt++;
776 }
777
778 fprintf(f, "], \"totalItems\": %d}", cnt);
779
780 fclose(f);
781}
782
783
708void import_blocked_accounts_csv(snac *user, const char *ifn) 784void import_blocked_accounts_csv(snac *user, const char *ifn)
709/* imports a Mastodon CSV file of blocked accounts */ 785/* imports a Mastodon CSV file of blocked accounts */
710{ 786{