Просмотр исходного кода

mastoapi: fixed uploaded images name collision.

grunfink 1 год назад
Родитель
Сommit
34d85b3e1b
2 измененных файлов с 5 добавлено и 3 удалено
  1. 1 1
      html.c
  2. 4 2
      mastoapi.c

+ 1 - 1
html.c

@@ -4362,7 +4362,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
                     xs_rnd_buf(rnd, sizeof(rnd));
                     xs_rnd_buf(rnd, sizeof(rnd));
 
 
                     const char *ext = strrchr(fn, '.');
                     const char *ext = strrchr(fn, '.');
-                    xs *hash  = xs_md5_hex(rnd, strlen(rnd));
+                    xs *hash  = xs_md5_hex(rnd, sizeof(rnd));
                     xs *id    = xs_fmt("post-%s%s", hash, ext ? ext : "");
                     xs *id    = xs_fmt("post-%s%s", hash, ext ? 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(attach_file, 1));
                     int fo    = xs_number_get(xs_list_get(attach_file, 1));

+ 4 - 2
mastoapi.c

@@ -2978,8 +2978,10 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
 
 
                 if (*fn != '\0') {
                 if (*fn != '\0') {
                     char *ext = strrchr(fn, '.');
                     char *ext = strrchr(fn, '.');
-                    xs *hash  = xs_md5_hex(fn, strlen(fn));
-                    xs *id    = xs_fmt("%s%s", hash, ext);
+                    char rnd[32];
+                    xs_rnd_buf(rnd, sizeof(rnd));
+                    xs *hash  = xs_md5_hex(rnd, sizeof(rnd));
+                    xs *id    = xs_fmt("post-%s%s", hash, ext ? 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(file, 1));
                     int fo    = xs_number_get(xs_list_get(file, 1));
                     int fs    = xs_number_get(xs_list_get(file, 2));
                     int fs    = xs_number_get(xs_list_get(file, 2));