summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorGravatar default2023-08-14 18:33:44 +0200
committerGravatar default2023-08-14 18:33:44 +0200
commit8b28a6894fd6aed3f2d7e46a443b02a2fdf7445c (patch)
tree051487243a9ec58908bc4c6d99eeded63f6683bb /html.c
parentFixed some warning. (diff)
downloadsnac2-8b28a6894fd6aed3f2d7e46a443b02a2fdf7445c.tar.gz
snac2-8b28a6894fd6aed3f2d7e46a443b02a2fdf7445c.tar.xz
snac2-8b28a6894fd6aed3f2d7e46a443b02a2fdf7445c.zip
Header banners can now be uploaded.
Diffstat (limited to 'html.c')
-rw-r--r--html.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/html.c b/html.c
index 51c5da2..8e45eba 100644
--- a/html.c
+++ b/html.c
@@ -556,6 +556,8 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
556 556
557 "<p>%s: <input type=\"file\" name=\"avatar_file\"></p>\n" 557 "<p>%s: <input type=\"file\" name=\"avatar_file\"></p>\n"
558 558
559 "<p>%s: <input type=\"file\" name=\"header_file\"></p>\n"
560
559 "<p>%s:<br>\n" 561 "<p>%s:<br>\n"
560 "<textarea name=\"bio\" cols=\"40\" rows=\"4\" placeholder=\"Write about yourself here...\">%s</textarea></p>\n" 562 "<textarea name=\"bio\" cols=\"40\" rows=\"4\" placeholder=\"Write about yourself here...\">%s</textarea></p>\n"
561 563
@@ -667,6 +669,7 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
667 L("Display name"), 669 L("Display name"),
668 es1, 670 es1,
669 L("Avatar"), 671 L("Avatar"),
672 L("Header image (banner)"),
670 L("Bio"), 673 L("Bio"),
671 es2, 674 es2,
672 strcmp(cw, "open") == 0 ? "checked" : "", 675 strcmp(cw, "open") == 0 ? "checked" : "",
@@ -2402,25 +2405,31 @@ int html_post_handler(const xs_dict *req, const char *q_path,
2402 else 2405 else
2403 snac.config = xs_dict_set(snac.config, "bot", xs_stock_false); 2406 snac.config = xs_dict_set(snac.config, "bot", xs_stock_false);
2404 2407
2405 /* avatar upload */ 2408 /* uploads */
2406 xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file"); 2409 const char *uploads[] = { "avatar", "header", NULL };
2407 if (xs_type(avatar_file) == XSTYPE_LIST) { 2410 int n;
2408 const char *fn = xs_list_get(avatar_file, 0); 2411 for (n = 0; uploads[n]; n++) {
2412 xs *var_name = xs_fmt("%s_file", uploads[n]);
2413
2414 xs_list *uploaded_file = xs_dict_get(p_vars, var_name);
2415 if (xs_type(uploaded_file) == XSTYPE_LIST) {
2416 const char *fn = xs_list_get(uploaded_file, 0);
2409 2417
2410 if (fn && *fn) { 2418 if (fn && *fn) {
2411 const char *mimetype = xs_mime_by_ext(fn); 2419 const char *mimetype = xs_mime_by_ext(fn);
2412 2420
2413 if (xs_startswith(mimetype, "image/")) { 2421 if (xs_startswith(mimetype, "image/")) {
2414 const char *ext = strrchr(fn, '.'); 2422 const char *ext = strrchr(fn, '.');
2415 xs *id = xs_fmt("avatar%s", ext); 2423 xs *id = xs_fmt("%s%s", uploads[n], ext);
2416 xs *url = xs_fmt("%s/s/%s", snac.actor, id); 2424 xs *url = xs_fmt("%s/s/%s", snac.actor, id);
2417 int fo = xs_number_get(xs_list_get(avatar_file, 1)); 2425 int fo = xs_number_get(xs_list_get(uploaded_file, 1));
2418 int fs = xs_number_get(xs_list_get(avatar_file, 2)); 2426 int fs = xs_number_get(xs_list_get(uploaded_file, 2));
2419 2427
2420 /* store */ 2428 /* store */
2421 static_put(&snac, id, payload + fo, fs); 2429 static_put(&snac, id, payload + fo, fs);
2422 2430
2423 snac.config = xs_dict_set(snac.config, "avatar", url); 2431 snac.config = xs_dict_set(snac.config, uploads[n], url);
2432 }
2424 } 2433 }
2425 } 2434 }
2426 } 2435 }