commit 8b28a68
default
·
2023-08-14 16:33:44 +0000 UTC
parent 8c87b68
Header banners can now be uploaded.
1 files changed,
+24,
-15
M
html.c
M
html.c
+24,
-15
1@@ -556,6 +556,8 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
2
3 "<p>%s: <input type=\"file\" name=\"avatar_file\"></p>\n"
4
5+ "<p>%s: <input type=\"file\" name=\"header_file\"></p>\n"
6+
7 "<p>%s:<br>\n"
8 "<textarea name=\"bio\" cols=\"40\" rows=\"4\" placeholder=\"Write about yourself here...\">%s</textarea></p>\n"
9
10@@ -667,6 +669,7 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
11 L("Display name"),
12 es1,
13 L("Avatar"),
14+ L("Header image (banner)"),
15 L("Bio"),
16 es2,
17 strcmp(cw, "open") == 0 ? "checked" : "",
18@@ -2402,25 +2405,31 @@ int html_post_handler(const xs_dict *req, const char *q_path,
19 else
20 snac.config = xs_dict_set(snac.config, "bot", xs_stock_false);
21
22- /* avatar upload */
23- xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file");
24- if (xs_type(avatar_file) == XSTYPE_LIST) {
25- const char *fn = xs_list_get(avatar_file, 0);
26+ /* uploads */
27+ const char *uploads[] = { "avatar", "header", NULL };
28+ int n;
29+ for (n = 0; uploads[n]; n++) {
30+ xs *var_name = xs_fmt("%s_file", uploads[n]);
31+
32+ xs_list *uploaded_file = xs_dict_get(p_vars, var_name);
33+ if (xs_type(uploaded_file) == XSTYPE_LIST) {
34+ const char *fn = xs_list_get(uploaded_file, 0);
35
36- if (fn && *fn) {
37- const char *mimetype = xs_mime_by_ext(fn);
38+ if (fn && *fn) {
39+ const char *mimetype = xs_mime_by_ext(fn);
40
41- if (xs_startswith(mimetype, "image/")) {
42- const char *ext = strrchr(fn, '.');
43- xs *id = xs_fmt("avatar%s", ext);
44- xs *url = xs_fmt("%s/s/%s", snac.actor, id);
45- int fo = xs_number_get(xs_list_get(avatar_file, 1));
46- int fs = xs_number_get(xs_list_get(avatar_file, 2));
47+ if (xs_startswith(mimetype, "image/")) {
48+ const char *ext = strrchr(fn, '.');
49+ xs *id = xs_fmt("%s%s", uploads[n], ext);
50+ xs *url = xs_fmt("%s/s/%s", snac.actor, id);
51+ int fo = xs_number_get(xs_list_get(uploaded_file, 1));
52+ int fs = xs_number_get(xs_list_get(uploaded_file, 2));
53
54- /* store */
55- static_put(&snac, id, payload + fo, fs);
56+ /* store */
57+ static_put(&snac, id, payload + fo, fs);
58
59- snac.config = xs_dict_set(snac.config, "avatar", url);
60+ snac.config = xs_dict_set(snac.config, uploads[n], url);
61+ }
62 }
63 }
64 }