diff options
| author | 2024-11-23 17:08:57 +0100 | |
|---|---|---|
| committer | 2024-11-23 17:08:57 +0100 | |
| commit | 09d268495c12d3c00a7293fbf445830bcc9d74c3 (patch) | |
| tree | 6a0f3838336ecc8679bedc78ff713c76ec4ef5c8 | |
| parent | Version 2.64 RELEASED. (diff) | |
| download | snac2-09d268495c12d3c00a7293fbf445830bcc9d74c3.tar.gz snac2-09d268495c12d3c00a7293fbf445830bcc9d74c3.tar.xz snac2-09d268495c12d3c00a7293fbf445830bcc9d74c3.zip | |
The 'metadata' field in user.json is now a string instead of a dict.
| -rw-r--r-- | activitypub.c | 25 | ||||
| -rw-r--r-- | html.c | 74 |
2 files changed, 69 insertions, 30 deletions
diff --git a/activitypub.c b/activitypub.c index 473675d..8c0c423 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1218,7 +1218,30 @@ xs_dict *msg_actor(snac *snac) | |||
| 1218 | } | 1218 | } |
| 1219 | 1219 | ||
| 1220 | /* add the metadata as attachments of PropertyValue */ | 1220 | /* add the metadata as attachments of PropertyValue */ |
| 1221 | const xs_dict *metadata = xs_dict_get(snac->config, "metadata"); | 1221 | xs *metadata = NULL; |
| 1222 | const xs_dict *md = xs_dict_get(snac->config, "metadata"); | ||
| 1223 | |||
| 1224 | if (xs_type(md) == XSTYPE_DICT) | ||
| 1225 | metadata = xs_dup(md); | ||
| 1226 | else | ||
| 1227 | if (xs_type(md) == XSTYPE_STRING) { | ||
| 1228 | metadata = xs_dict_new(); | ||
| 1229 | xs *l = xs_split(md, "\r\n"); | ||
| 1230 | const char *ll; | ||
| 1231 | |||
| 1232 | xs_list_foreach(l, ll) { | ||
| 1233 | xs *kv = xs_split_n(ll, "=", 1); | ||
| 1234 | const char *k = xs_list_get(kv, 0); | ||
| 1235 | const char *v = xs_list_get(kv, 1); | ||
| 1236 | |||
| 1237 | if (k && v) { | ||
| 1238 | xs *kk = xs_strip_i(xs_dup(k)); | ||
| 1239 | xs *vv = xs_strip_i(xs_dup(v)); | ||
| 1240 | metadata = xs_dict_set(metadata, kk, vv); | ||
| 1241 | } | ||
| 1242 | } | ||
| 1243 | } | ||
| 1244 | |||
| 1222 | if (xs_type(metadata) == XSTYPE_DICT) { | 1245 | if (xs_type(metadata) == XSTYPE_DICT) { |
| 1223 | xs *attach = xs_list_new(); | 1246 | xs *attach = xs_list_new(); |
| 1224 | const xs_str *k; | 1247 | const xs_str *k; |
| @@ -843,7 +843,31 @@ static xs_html *html_user_body(snac *user, int read_only) | |||
| 843 | xs_html_add(top_user, | 843 | xs_html_add(top_user, |
| 844 | top_user_bio); | 844 | top_user_bio); |
| 845 | 845 | ||
| 846 | const xs_dict *metadata = xs_dict_get(user->config, "metadata"); | 846 | xs *metadata = NULL; |
| 847 | const xs_dict *md = xs_dict_get(user->config, "metadata"); | ||
| 848 | |||
| 849 | if (xs_type(md) == XSTYPE_DICT) | ||
| 850 | metadata = xs_dup(md); | ||
| 851 | else | ||
| 852 | if (xs_type(md) == XSTYPE_STRING) { | ||
| 853 | /* convert to dict for easier iteration */ | ||
| 854 | metadata = xs_dict_new(); | ||
| 855 | xs *l = xs_split(md, "\r\n"); | ||
| 856 | const char *ll; | ||
| 857 | |||
| 858 | xs_list_foreach(l, ll) { | ||
| 859 | xs *kv = xs_split_n(ll, "=", 1); | ||
| 860 | const char *k = xs_list_get(kv, 0); | ||
| 861 | const char *v = xs_list_get(kv, 1); | ||
| 862 | |||
| 863 | if (k && v) { | ||
| 864 | xs *kk = xs_strip_i(xs_dup(k)); | ||
| 865 | xs *vv = xs_strip_i(xs_dup(v)); | ||
| 866 | metadata = xs_dict_set(metadata, kk, vv); | ||
| 867 | } | ||
| 868 | } | ||
| 869 | } | ||
| 870 | |||
| 847 | if (xs_type(metadata) == XSTYPE_DICT) { | 871 | if (xs_type(metadata) == XSTYPE_DICT) { |
| 848 | const xs_str *k; | 872 | const xs_str *k; |
| 849 | const xs_str *v; | 873 | const xs_str *v; |
| @@ -1026,19 +1050,28 @@ xs_html *html_top_controls(snac *snac) | |||
| 1026 | const xs_val *auto_boost = xs_dict_get(snac->config, "auto_boost"); | 1050 | const xs_val *auto_boost = xs_dict_get(snac->config, "auto_boost"); |
| 1027 | const xs_val *coll_thrds = xs_dict_get(snac->config, "collapse_threads"); | 1051 | const xs_val *coll_thrds = xs_dict_get(snac->config, "collapse_threads"); |
| 1028 | 1052 | ||
| 1029 | xs *metadata = xs_str_new(NULL); | 1053 | xs *metadata = NULL; |
| 1030 | const xs_dict *md = xs_dict_get(snac->config, "metadata"); | 1054 | const xs_dict *md = xs_dict_get(snac->config, "metadata"); |
| 1031 | const xs_str *k; | ||
| 1032 | const xs_str *v; | ||
| 1033 | 1055 | ||
| 1034 | int c = 0; | 1056 | if (xs_type(md) == XSTYPE_DICT) { |
| 1035 | while (xs_dict_next(md, &k, &v, &c)) { | 1057 | const xs_str *k; |
| 1036 | xs *kp = xs_fmt("%s=%s", k, v); | 1058 | const xs_str *v; |
| 1059 | |||
| 1060 | metadata = xs_str_new(NULL); | ||
| 1037 | 1061 | ||
| 1038 | if (*metadata) | 1062 | xs_dict_foreach(md, k, v) { |
| 1039 | metadata = xs_str_cat(metadata, "\n"); | 1063 | xs *kp = xs_fmt("%s=%s", k, v); |
| 1040 | metadata = xs_str_cat(metadata, kp); | 1064 | |
| 1065 | if (*metadata) | ||
| 1066 | metadata = xs_str_cat(metadata, "\n"); | ||
| 1067 | metadata = xs_str_cat(metadata, kp); | ||
| 1068 | } | ||
| 1041 | } | 1069 | } |
| 1070 | else | ||
| 1071 | if (xs_type(md) == XSTYPE_STRING) | ||
| 1072 | metadata = xs_dup(md); | ||
| 1073 | else | ||
| 1074 | metadata = xs_str_new(NULL); | ||
| 1042 | 1075 | ||
| 1043 | xs *user_setup_action = xs_fmt("%s/admin/user-setup", snac->actor); | 1076 | xs *user_setup_action = xs_fmt("%s/admin/user-setup", snac->actor); |
| 1044 | 1077 | ||
| @@ -3706,25 +3739,8 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 3706 | else | 3739 | else |
| 3707 | snac.config = xs_dict_set(snac.config, "collapse_threads", xs_stock(XSTYPE_FALSE)); | 3740 | snac.config = xs_dict_set(snac.config, "collapse_threads", xs_stock(XSTYPE_FALSE)); |
| 3708 | 3741 | ||
| 3709 | if ((v = xs_dict_get(p_vars, "metadata")) != NULL) { | 3742 | if ((v = xs_dict_get(p_vars, "metadata")) != NULL) |
| 3710 | /* split the metadata and store it as a dict */ | 3743 | snac.config = xs_dict_set(snac.config, "metadata", v); |
| 3711 | xs_dict *md = xs_dict_new(); | ||
| 3712 | xs *l = xs_split(v, "\n"); | ||
| 3713 | xs_list *p = l; | ||
| 3714 | const xs_str *kp; | ||
| 3715 | |||
| 3716 | while (xs_list_iter(&p, &kp)) { | ||
| 3717 | xs *kpl = xs_split_n(kp, "=", 1); | ||
| 3718 | if (xs_list_len(kpl) == 2) { | ||
| 3719 | xs *k2 = xs_strip_i(xs_dup(xs_list_get(kpl, 0))); | ||
| 3720 | xs *v2 = xs_strip_i(xs_dup(xs_list_get(kpl, 1))); | ||
| 3721 | |||
| 3722 | md = xs_dict_set(md, k2, v2); | ||
| 3723 | } | ||
| 3724 | } | ||
| 3725 | |||
| 3726 | snac.config = xs_dict_set(snac.config, "metadata", md); | ||
| 3727 | } | ||
| 3728 | 3744 | ||
| 3729 | /* uploads */ | 3745 | /* uploads */ |
| 3730 | const char *uploads[] = { "avatar", "header", NULL }; | 3746 | const char *uploads[] = { "avatar", "header", NULL }; |