Header banners can now be uploaded.

This commit is contained in:
default 2023-08-14 18:33:44 +02:00
parent 8c87b6894e
commit 8b28a6894f

25
html.c
View file

@ -556,6 +556,8 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
"<p>%s: <input type=\"file\" name=\"avatar_file\"></p>\n" "<p>%s: <input type=\"file\" name=\"avatar_file\"></p>\n"
"<p>%s: <input type=\"file\" name=\"header_file\"></p>\n"
"<p>%s:<br>\n" "<p>%s:<br>\n"
"<textarea name=\"bio\" cols=\"40\" rows=\"4\" placeholder=\"Write about yourself here...\">%s</textarea></p>\n" "<textarea name=\"bio\" cols=\"40\" rows=\"4\" placeholder=\"Write about yourself here...\">%s</textarea></p>\n"
@ -667,6 +669,7 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
L("Display name"), L("Display name"),
es1, es1,
L("Avatar"), L("Avatar"),
L("Header image (banner)"),
L("Bio"), L("Bio"),
es2, es2,
strcmp(cw, "open") == 0 ? "checked" : "", strcmp(cw, "open") == 0 ? "checked" : "",
@ -2402,25 +2405,31 @@ int html_post_handler(const xs_dict *req, const char *q_path,
else else
snac.config = xs_dict_set(snac.config, "bot", xs_stock_false); snac.config = xs_dict_set(snac.config, "bot", xs_stock_false);
/* avatar upload */ /* uploads */
xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file"); const char *uploads[] = { "avatar", "header", NULL };
if (xs_type(avatar_file) == XSTYPE_LIST) { int n;
const char *fn = xs_list_get(avatar_file, 0); for (n = 0; uploads[n]; n++) {
xs *var_name = xs_fmt("%s_file", uploads[n]);
xs_list *uploaded_file = xs_dict_get(p_vars, var_name);
if (xs_type(uploaded_file) == XSTYPE_LIST) {
const char *fn = xs_list_get(uploaded_file, 0);
if (fn && *fn) { if (fn && *fn) {
const char *mimetype = xs_mime_by_ext(fn); const char *mimetype = xs_mime_by_ext(fn);
if (xs_startswith(mimetype, "image/")) { if (xs_startswith(mimetype, "image/")) {
const char *ext = strrchr(fn, '.'); const char *ext = strrchr(fn, '.');
xs *id = xs_fmt("avatar%s", ext); xs *id = xs_fmt("%s%s", uploads[n], ext);
xs *url = xs_fmt("%s/s/%s", snac.actor, id); xs *url = xs_fmt("%s/s/%s", snac.actor, id);
int fo = xs_number_get(xs_list_get(avatar_file, 1)); int fo = xs_number_get(xs_list_get(uploaded_file, 1));
int fs = xs_number_get(xs_list_get(avatar_file, 2)); int fs = xs_number_get(xs_list_get(uploaded_file, 2));
/* store */ /* store */
static_put(&snac, id, payload + fo, fs); static_put(&snac, id, payload + fo, fs);
snac.config = xs_dict_set(snac.config, "avatar", url); snac.config = xs_dict_set(snac.config, uploads[n], url);
}
} }
} }
} }