From 5b4615da674a855fa8b67c0b186e20416fa1edae Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Thu, 29 May 2025 15:11:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactor=20of=20config=20to=20ad?= =?UTF-8?q?d=20it=20in=20DB=20for=20admin=20part?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/config.py | 35 ++++++++++++++++++++++++++--------- app/models/config.py | 16 ++++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 app/models/config.py diff --git a/app/config.py b/app/config.py index 0c932af..5975e98 100644 --- a/app/config.py +++ b/app/config.py @@ -9,16 +9,33 @@ MONGODB_DATABASE = os.getenv("MONGODB_DATABASE", "memorymap") # Constants for JWT SECRET_KEY = os.getenv("JWT_SECRET_KEY", "_2YfT44$xF.Tg_xI63UH3D7:N+>pZN2';j%>7H@?e0:Xor'pV[") # temporary of course :) ALGORITHM = os.getenv("JWT_ALGORITHM", "HS256") -ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("JWT_ACCESS_TOKEN_EXPIRE_MINUTES", 30)) # TODO: check what to add here / maybe need to evaluate criticity of that? +ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("JWT_ACCESS_TOKEN_EXPIRE_MINUTES", 30)) # Constants for OAuth2 TOKEN_URL = "/api/v1/login" # Path to the auth -# Constants for images -UPLOAD_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "images") -MAX_IMAGE_SIZE = 8 * 1024 * 1024 # 8 Mo -ALLOWED_MIME_TYPES = [ - "image/jpeg", - "image/png", - "image/heic" -] \ No newline at end of file +# Constants for config +UPLOAD_DIR = os.getenv("UPLOAD_DIR", os.path.join(os.path.dirname(os.path.dirname(__file__)), "images")) + +# Configuration par défaut du système +DEFAULT_CONFIG = { + "max_image_size": 8 * 1024 * 1024, # 8MB + "max_images_per_pin": 10, + "max_images_per_user": 100, + "allowed_image_types": [ + "image/jpeg", + "image/png", + "image/gif", + "image/webp" + ], + "max_pins_per_user": 50, + "max_friends_per_user": 100 +} + +# Configuration actuelle (sera mise à jour au démarrage) +MAX_IMAGE_SIZE = DEFAULT_CONFIG["max_image_size"] +MAX_IMAGES_PER_PIN = DEFAULT_CONFIG["max_images_per_pin"] +MAX_IMAGES_PER_USER = DEFAULT_CONFIG["max_images_per_user"] +ALLOWED_MIME_TYPES = DEFAULT_CONFIG["allowed_image_types"] +MAX_PINS_PER_USER = DEFAULT_CONFIG["max_pins_per_user"] +MAX_FRIENDS_PER_USER = DEFAULT_CONFIG["max_friends_per_user"] diff --git a/app/models/config.py b/app/models/config.py new file mode 100644 index 0000000..1bdb069 --- /dev/null +++ b/app/models/config.py @@ -0,0 +1,16 @@ +from pydantic import BaseModel +from typing import List +from datetime import datetime + +class SystemConfig(BaseModel): + max_image_size: int # en octets + max_images_per_pin: int + max_images_per_user: int + allowed_image_types: List[str] # types MIME + max_pins_per_user: int + max_friends_per_user: int + +class DBConfig(BaseModel): + config: SystemConfig + updated_at: datetime + updated_by: str # ID de l'utilisateur qui a fait la dernière modification \ No newline at end of file