diff options
Diffstat (limited to '')
| -rw-r--r-- | data.c | 101 |
1 files changed, 94 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* snac - A simple, minimalistic ActivityPub instance */ | 1 | /* snac - A simple, minimalistic ActivityPub instance */ |
| 2 | /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ | 2 | /* copyright (c) 2022 - 2026 grunfink et al. / MIT license */ |
| 3 | 3 | ||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_hex.h" | 5 | #include "xs_hex.h" |
| @@ -41,6 +41,20 @@ int srv_open(const char *basedir, int auto_upgrade) | |||
| 41 | FILE *f; | 41 | FILE *f; |
| 42 | xs_str *error = NULL; | 42 | xs_str *error = NULL; |
| 43 | 43 | ||
| 44 | /* MUST be three letters */ | ||
| 45 | months[0] = LL("Jan"); | ||
| 46 | months[1] = LL("Feb"); | ||
| 47 | months[2] = LL("Mar"); | ||
| 48 | months[3] = LL("Apr"); | ||
| 49 | months[4] = LL("May"); | ||
| 50 | months[5] = LL("Jun"); | ||
| 51 | months[6] = LL("Jul"); | ||
| 52 | months[7] = LL("Aug"); | ||
| 53 | months[8] = LL("Sep"); | ||
| 54 | months[9] = LL("Oct"); | ||
| 55 | months[10] = LL("Nov"); | ||
| 56 | months[11] = LL("Dec"); | ||
| 57 | |||
| 44 | pthread_mutex_init(&data_mutex, NULL); | 58 | pthread_mutex_init(&data_mutex, NULL); |
| 45 | 59 | ||
| 46 | srv_basedir = xs_str_new(basedir); | 60 | srv_basedir = xs_str_new(basedir); |
| @@ -89,8 +103,15 @@ int srv_open(const char *basedir, int auto_upgrade) | |||
| 89 | else { | 103 | else { |
| 90 | if (xs_number_get(xs_dict_get(srv_config, "layout")) < disk_layout) | 104 | if (xs_number_get(xs_dict_get(srv_config, "layout")) < disk_layout) |
| 91 | error = xs_fmt("ERROR: disk layout changed - execute 'snac upgrade' first"); | 105 | error = xs_fmt("ERROR: disk layout changed - execute 'snac upgrade' first"); |
| 92 | else | 106 | else { |
| 93 | ret = 1; | 107 | if (!check_strip_tool()) { |
| 108 | const char *mp = xs_dict_get(srv_config, "mogrify_path"); | ||
| 109 | if (mp == NULL) mp = "mogrify"; | ||
| 110 | error = xs_fmt("ERROR: strip_exif enabled but '%s' not found or not working (set 'mogrify_path' in server.json)", mp); | ||
| 111 | } | ||
| 112 | else | ||
| 113 | ret = 1; | ||
| 114 | } | ||
| 94 | } | 115 | } |
| 95 | } | 116 | } |
| 96 | 117 | ||
| @@ -2368,9 +2389,9 @@ void tag_index(const char *id, const xs_dict *obj) | |||
| 2368 | if (*name == '\0') | 2389 | if (*name == '\0') |
| 2369 | continue; | 2390 | continue; |
| 2370 | 2391 | ||
| 2371 | name = xs_utf8_to_lower((xs_str *)name); | 2392 | xs* name_cased = xs_utf8_to_lower((xs_str *)name); |
| 2372 | 2393 | ||
| 2373 | xs *md5_tag = xs_md5_hex(name, strlen(name)); | 2394 | xs *md5_tag = xs_md5_hex(name_cased, strlen(name_cased)); |
| 2374 | xs *tag_dir = xs_fmt("%s/%c%c", g_tag_dir, md5_tag[0], md5_tag[1]); | 2395 | xs *tag_dir = xs_fmt("%s/%c%c", g_tag_dir, md5_tag[0], md5_tag[1]); |
| 2375 | mkdirx(tag_dir); | 2396 | mkdirx(tag_dir); |
| 2376 | 2397 | ||
| @@ -2382,7 +2403,7 @@ void tag_index(const char *id, const xs_dict *obj) | |||
| 2382 | FILE *f; | 2403 | FILE *f; |
| 2383 | xs *g_tag_name = xs_replace(g_tag_idx, ".idx", ".tag"); | 2404 | xs *g_tag_name = xs_replace(g_tag_idx, ".idx", ".tag"); |
| 2384 | if ((f = fopen(g_tag_name, "w")) != NULL) { | 2405 | if ((f = fopen(g_tag_name, "w")) != NULL) { |
| 2385 | fprintf(f, "%s\n", name); | 2406 | fprintf(f, "%s\n", name_cased); |
| 2386 | fclose(f); | 2407 | fclose(f); |
| 2387 | } | 2408 | } |
| 2388 | 2409 | ||
| @@ -2710,6 +2731,8 @@ void static_put(snac *snac, const char *id, const char *data, int size) | |||
| 2710 | if (fn && (f = fopen(fn, "wb")) != NULL) { | 2731 | if (fn && (f = fopen(fn, "wb")) != NULL) { |
| 2711 | fwrite(data, size, 1, f); | 2732 | fwrite(data, size, 1, f); |
| 2712 | fclose(f); | 2733 | fclose(f); |
| 2734 | |||
| 2735 | strip_media(fn); | ||
| 2713 | } | 2736 | } |
| 2714 | } | 2737 | } |
| 2715 | 2738 | ||
| @@ -3494,11 +3517,75 @@ xs_list *notify_list(snac *snac, int skip, int show) | |||
| 3494 | } | 3517 | } |
| 3495 | 3518 | ||
| 3496 | 3519 | ||
| 3520 | xs_list *notify_filter_list(snac *snac, xs_list *notifs) | ||
| 3521 | /* apply user-defined notification filter to IDs */ | ||
| 3522 | { | ||
| 3523 | const xs_dict *n_filter = xs_dict_get(snac->config, "notify_filter"); | ||
| 3524 | if (!n_filter) { | ||
| 3525 | return xs_dup(notifs); | ||
| 3526 | } | ||
| 3527 | const xs_val *n_def = xs_stock( XSTYPE_TRUE ); | ||
| 3528 | int n_likes_on = xs_is_true(xs_dict_get_def(n_filter, "likes", n_def)); | ||
| 3529 | int n_reacts_on = xs_is_true(xs_dict_get_def(n_filter, "reacts", n_def)); | ||
| 3530 | int n_ments_on = xs_is_true(xs_dict_get_def(n_filter, "mentions", n_def)); | ||
| 3531 | int n_ann_on = xs_is_true(xs_dict_get_def(n_filter, "announces", n_def)); | ||
| 3532 | int n_fol_on = xs_is_true(xs_dict_get_def(n_filter, "follows", n_def)); | ||
| 3533 | int n_unfol_on = xs_is_true(xs_dict_get_def(n_filter, "unfollows", n_def)); | ||
| 3534 | int n_folreq_on = xs_is_true(xs_dict_get_def(n_filter, "folreqs", n_def)); | ||
| 3535 | int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def)); | ||
| 3536 | int n_polls_on = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def)); | ||
| 3537 | |||
| 3538 | const xs_str *v; | ||
| 3539 | xs_list *flt = xs_list_new(); | ||
| 3540 | |||
| 3541 | xs_list_foreach(notifs, v) { | ||
| 3542 | xs *noti = notify_get(snac, v); | ||
| 3543 | |||
| 3544 | if (noti == NULL) | ||
| 3545 | continue; | ||
| 3546 | |||
| 3547 | const char *type = xs_dict_get(noti, "type"); | ||
| 3548 | const char *utype = xs_dict_get(noti, "utype"); | ||
| 3549 | const char *actor_id = xs_dict_get(noti, "actor"); | ||
| 3550 | if (strcmp(type, "EmojiReact") == 0 && xs_is_true(xs_dict_get(srv_config, "disable_emojireact"))) | ||
| 3551 | continue; | ||
| 3552 | if (strcmp(type, "Create") == 0 && !n_ments_on) | ||
| 3553 | continue; | ||
| 3554 | if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0 && !n_polls_on) | ||
| 3555 | continue; | ||
| 3556 | if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") == 0 && !n_unfol_on) | ||
| 3557 | continue; | ||
| 3558 | if (strcmp(type, "EmojiReact") == 0 || strcmp(type, "Like") == 0) { | ||
| 3559 | if (strcmp(type, "Like") == 0 && !n_likes_on) | ||
| 3560 | continue; | ||
| 3561 | if (strcmp(type, "EmojiReact") == 0 && !n_reacts_on) | ||
| 3562 | continue; | ||
| 3563 | } | ||
| 3564 | if (strcmp(type, "Follow") == 0) { | ||
| 3565 | if (pending_check(snac, actor_id)) { | ||
| 3566 | if (!n_folreq_on) | ||
| 3567 | continue; | ||
| 3568 | } | ||
| 3569 | else | ||
| 3570 | if (!n_fol_on) | ||
| 3571 | continue; | ||
| 3572 | } | ||
| 3573 | if (strcmp(type, "Block") == 0 && !n_blocks_on) | ||
| 3574 | continue; | ||
| 3575 | if (strcmp(type, "Announce") == 0 && !n_ann_on) | ||
| 3576 | continue; | ||
| 3577 | flt = xs_list_append(flt, v); | ||
| 3578 | } | ||
| 3579 | return flt; | ||
| 3580 | } | ||
| 3581 | |||
| 3582 | |||
| 3497 | int notify_new_num(snac *snac) | 3583 | int notify_new_num(snac *snac) |
| 3498 | /* counts the number of new notifications */ | 3584 | /* counts the number of new notifications */ |
| 3499 | { | 3585 | { |
| 3500 | xs *t = notify_check_time(snac, 0); | 3586 | xs *t = notify_check_time(snac, 0); |
| 3501 | xs *lst = notify_list(snac, 0, XS_ALL); | 3587 | xs *lst_unfilt = notify_list(snac, 0, XS_ALL); |
| 3588 | xs *lst = notify_filter_list(snac, lst_unfilt); | ||
| 3502 | int cnt = 0; | 3589 | int cnt = 0; |
| 3503 | 3590 | ||
| 3504 | xs_list *p = lst; | 3591 | xs_list *p = lst; |