diff options
| author | 2023-08-14 15:12:09 +0200 | |
|---|---|---|
| committer | 2023-08-14 15:12:09 +0200 | |
| commit | 16c14060a81d4f7ed6be0bf5f95ca3c77733c18f (patch) | |
| tree | d6bb1942d5e6daa537e715b7a5e02ce4fc9342ef | |
| parent | If the user has a header image, show it the public page. (diff) | |
| download | snac2-16c14060a81d4f7ed6be0bf5f95ca3c77733c18f.tar.gz snac2-16c14060a81d4f7ed6be0bf5f95ca3c77733c18f.tar.xz snac2-16c14060a81d4f7ed6be0bf5f95ca3c77733c18f.zip | |
Discard avatar uploads that are not images.
| -rw-r--r-- | html.c | 26 |
1 files changed, 15 insertions, 11 deletions
| @@ -2415,20 +2415,24 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 2415 | 2415 | ||
| 2416 | /* avatar upload */ | 2416 | /* avatar upload */ |
| 2417 | xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file"); | 2417 | xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file"); |
| 2418 | if (!xs_is_null(avatar_file) && xs_type(avatar_file) == XSTYPE_LIST) { | 2418 | if (xs_type(avatar_file) == XSTYPE_LIST) { |
| 2419 | char *fn = xs_list_get(avatar_file, 0); | 2419 | const char *fn = xs_list_get(avatar_file, 0); |
| 2420 | 2420 | ||
| 2421 | if (*fn != '\0') { | 2421 | if (fn && *fn) { |
| 2422 | char *ext = strrchr(fn, '.'); | 2422 | const char *mimetype = xs_mime_by_ext(fn); |
| 2423 | xs *id = xs_fmt("avatar%s", ext); | ||
| 2424 | xs *url = xs_fmt("%s/s/%s", snac.actor, id); | ||
| 2425 | int fo = xs_number_get(xs_list_get(avatar_file, 1)); | ||
| 2426 | int fs = xs_number_get(xs_list_get(avatar_file, 2)); | ||
| 2427 | 2423 | ||
| 2428 | /* store */ | 2424 | if (xs_startswith(mimetype, "image/")) { |
| 2429 | static_put(&snac, id, payload + fo, fs); | 2425 | const char *ext = strrchr(fn, '.'); |
| 2426 | xs *id = xs_fmt("avatar%s", ext); | ||
| 2427 | xs *url = xs_fmt("%s/s/%s", snac.actor, id); | ||
| 2428 | int fo = xs_number_get(xs_list_get(avatar_file, 1)); | ||
| 2429 | int fs = xs_number_get(xs_list_get(avatar_file, 2)); | ||
| 2430 | |||
| 2431 | /* store */ | ||
| 2432 | static_put(&snac, id, payload + fo, fs); | ||
| 2430 | 2433 | ||
| 2431 | snac.config = xs_dict_set(snac.config, "avatar", url); | 2434 | snac.config = xs_dict_set(snac.config, "avatar", url); |
| 2435 | } | ||
| 2432 | } | 2436 | } |
| 2433 | } | 2437 | } |
| 2434 | 2438 | ||