Cleanip init.py, utils.py and decorators.py

This commit is contained in:
2025-04-17 13:59:42 +02:00
parent 3b0bc856e9
commit 235072af97
5 changed files with 22 additions and 8 deletions

View File

@@ -1,17 +1,23 @@
from werkzeug.utils import secure_filename
import os
from werkzeug.utils import secure_filename
from application import app
from flask_login import current_user # type: ignore
# save image to static folder
def saveImage(image: ...):
filename = secure_filename(image.filename)
# Path should be /application/static/[user_id]/[filename]
save_path = os.path.join(
app.config["UPLOAD_FOLDER"], # type: ignore
str(current_user.id),
filename,
)
# Create path is it doesn't exist
os.makedirs(os.path.dirname(save_path), exist_ok=True)
# Save the image
image.save(save_path) # type: ignore
filename2 = str(current_user.id) + "/" + filename
# Return the filename that is stored in database.
# Only done to keep a single default image, this should be done differently
filename2 = str(current_user.id) + "/" + filename # [user_id]/[filename]
return filename2