From 9fcaf7245771aba39c4774f6138495c8dc3e3484 Mon Sep 17 00:00:00 2001 From: cube Date: Fri, 1 May 2026 17:26:20 +0100 Subject: [PATCH] images with same file name wont overwrite each other --- myriad/manage.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/myriad/manage.py b/myriad/manage.py index 58d4ae9..36f310c 100644 --- a/myriad/manage.py +++ b/myriad/manage.py @@ -774,7 +774,18 @@ def assets(): if "image" in request.files: file = request.files["image"] filename = file.filename - file.save(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], filename)) + fname, ftype = filename.split(".") + + i = 0 + if os.path.exists(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], filename)): + i = 2 + while os.path.exists(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], fname+str(i)+"."+ftype)): + i += 1 + + if i == 0: + file.save(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], filename)) + else: + file.save(os.path.join(current_app.config["MISC_UPLOAD_FOLDER"], fname+str(i)+"."+ftype)) icons = db.execute("SELECT * FROM icons").fetchall() icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"])