mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Header banners can now be uploaded.
This commit is contained in:
parent
8c87b6894e
commit
8b28a6894f
1 changed files with 24 additions and 15 deletions
39
html.c
39
html.c
|
@ -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]);
|
||||||
|
|
||||||
if (fn && *fn) {
|
xs_list *uploaded_file = xs_dict_get(p_vars, var_name);
|
||||||
const char *mimetype = xs_mime_by_ext(fn);
|
if (xs_type(uploaded_file) == XSTYPE_LIST) {
|
||||||
|
const char *fn = xs_list_get(uploaded_file, 0);
|
||||||
|
|
||||||
if (xs_startswith(mimetype, "image/")) {
|
if (fn && *fn) {
|
||||||
const char *ext = strrchr(fn, '.');
|
const char *mimetype = xs_mime_by_ext(fn);
|
||||||
xs *id = xs_fmt("avatar%s", ext);
|
|
||||||
xs *url = xs_fmt("%s/s/%s", snac.actor, id);
|
|
||||||
int fo = xs_number_get(xs_list_get(avatar_file, 1));
|
|
||||||
int fs = xs_number_get(xs_list_get(avatar_file, 2));
|
|
||||||
|
|
||||||
/* store */
|
if (xs_startswith(mimetype, "image/")) {
|
||||||
static_put(&snac, id, payload + fo, fs);
|
const char *ext = strrchr(fn, '.');
|
||||||
|
xs *id = xs_fmt("%s%s", uploads[n], ext);
|
||||||
|
xs *url = xs_fmt("%s/s/%s", snac.actor, id);
|
||||||
|
int fo = xs_number_get(xs_list_get(uploaded_file, 1));
|
||||||
|
int fs = xs_number_get(xs_list_get(uploaded_file, 2));
|
||||||
|
|
||||||
snac.config = xs_dict_set(snac.config, "avatar", url);
|
/* store */
|
||||||
|
static_put(&snac, id, payload + fo, fs);
|
||||||
|
|
||||||
|
snac.config = xs_dict_set(snac.config, uploads[n], url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue