commit 34d85b3

grunfink  ·  2025-05-29 11:12:43 +0000 UTC
parent 77b9cbe
mastoapi: fixed uploaded images name collision.
2 files changed,  +5, -3
M html.c
M html.c
+1, -1
1@@ -4362,7 +4362,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
2                     xs_rnd_buf(rnd, sizeof(rnd));
3 
4                     const char *ext = strrchr(fn, '.');
5-                    xs *hash  = xs_md5_hex(rnd, strlen(rnd));
6+                    xs *hash  = xs_md5_hex(rnd, sizeof(rnd));
7                     xs *id    = xs_fmt("post-%s%s", hash, ext ? ext : "");
8                     xs *url   = xs_fmt("%s/s/%s", snac.actor, id);
9                     int fo    = xs_number_get(xs_list_get(attach_file, 1));
+4, -2
 1@@ -2978,8 +2978,10 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
 2 
 3                 if (*fn != '\0') {
 4                     char *ext = strrchr(fn, '.');
 5-                    xs *hash  = xs_md5_hex(fn, strlen(fn));
 6-                    xs *id    = xs_fmt("%s%s", hash, ext);
 7+                    char rnd[32];
 8+                    xs_rnd_buf(rnd, sizeof(rnd));
 9+                    xs *hash  = xs_md5_hex(rnd, sizeof(rnd));
10+                    xs *id    = xs_fmt("post-%s%s", hash, ext ? ext : "");
11                     xs *url   = xs_fmt("%s/s/%s", snac.actor, id);
12                     int fo    = xs_number_get(xs_list_get(file, 1));
13                     int fs    = xs_number_get(xs_list_get(file, 2));