diff options
| author | 2025-05-29 13:12:43 +0200 | |
|---|---|---|
| committer | 2025-05-29 13:12:43 +0200 | |
| commit | 34d85b3e1bbda2e89191026b3815dd9b6f23afcb (patch) | |
| tree | 631e216fb24ae3dd028ebb4043364de88c80d7df | |
| parent | Added more checks. (diff) | |
| download | snac2-34d85b3e1bbda2e89191026b3815dd9b6f23afcb.tar.gz snac2-34d85b3e1bbda2e89191026b3815dd9b6f23afcb.tar.xz snac2-34d85b3e1bbda2e89191026b3815dd9b6f23afcb.zip | |
mastoapi: fixed uploaded images name collision.
| -rw-r--r-- | html.c | 2 | ||||
| -rw-r--r-- | mastoapi.c | 6 |
2 files changed, 5 insertions, 3 deletions
| @@ -4362,7 +4362,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 4362 | xs_rnd_buf(rnd, sizeof(rnd)); | 4362 | xs_rnd_buf(rnd, sizeof(rnd)); |
| 4363 | 4363 | ||
| 4364 | const char *ext = strrchr(fn, '.'); | 4364 | const char *ext = strrchr(fn, '.'); |
| 4365 | xs *hash = xs_md5_hex(rnd, strlen(rnd)); | 4365 | xs *hash = xs_md5_hex(rnd, sizeof(rnd)); |
| 4366 | xs *id = xs_fmt("post-%s%s", hash, ext ? ext : ""); | 4366 | xs *id = xs_fmt("post-%s%s", hash, ext ? ext : ""); |
| 4367 | xs *url = xs_fmt("%s/s/%s", snac.actor, id); | 4367 | xs *url = xs_fmt("%s/s/%s", snac.actor, id); |
| 4368 | int fo = xs_number_get(xs_list_get(attach_file, 1)); | 4368 | int fo = xs_number_get(xs_list_get(attach_file, 1)); |
| @@ -2978,8 +2978,10 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 2978 | 2978 | ||
| 2979 | if (*fn != '\0') { | 2979 | if (*fn != '\0') { |
| 2980 | char *ext = strrchr(fn, '.'); | 2980 | char *ext = strrchr(fn, '.'); |
| 2981 | xs *hash = xs_md5_hex(fn, strlen(fn)); | 2981 | char rnd[32]; |
| 2982 | xs *id = xs_fmt("%s%s", hash, ext); | 2982 | xs_rnd_buf(rnd, sizeof(rnd)); |
| 2983 | xs *hash = xs_md5_hex(rnd, sizeof(rnd)); | ||
| 2984 | xs *id = xs_fmt("post-%s%s", hash, ext ? ext : ""); | ||
| 2983 | xs *url = xs_fmt("%s/s/%s", snac.actor, id); | 2985 | xs *url = xs_fmt("%s/s/%s", snac.actor, id); |
| 2984 | int fo = xs_number_get(xs_list_get(file, 1)); | 2986 | int fo = xs_number_get(xs_list_get(file, 1)); |
| 2985 | int fs = xs_number_get(xs_list_get(file, 2)); | 2987 | int fs = xs_number_get(xs_list_get(file, 2)); |