diff options
Diffstat (limited to 'src/app.py')
| -rw-r--r-- | src/app.py | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -5,6 +5,7 @@ import hashlib import os import re import secrets +import string import subprocess import time from pathlib import Path @@ -215,7 +216,7 @@ def favicon_svg(): @app.route("/nyan.png") def nyan_png(): - return send_from_directory(app.root_path, "nyan.png") + return send_from_directory(UPLOAD_DIR, "nyan.png") @app.route("/uploads/<filename>") @@ -244,7 +245,9 @@ def upload(): ext = ALLOWED_MIME[mime] basename = re.sub(r"[^a-zA-Z0-9_-]", "_", Path(f.filename).stem)[:64] or "image" - filename = f"{basename}_{secrets.token_hex(4)}.{ext}" + epoch = int(time.time()) + rand = "".join(secrets.choice(string.ascii_lowercase + string.digits) for _ in range(16)) + filename = f"{basename}_{epoch}-{rand}.{ext}" (UPLOAD_DIR / filename).write_bytes(data) |
