images with same file name wont overwrite each other

This commit is contained in:
cube
2026-05-01 17:26:20 +01:00
parent 0df4bf926b
commit 9fcaf72457

View File

@@ -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"])