- Upload de GIF/MP4/WebM comme animations de compte a rebours - Checkboxes pour activer/desactiver chaque animation (CSS + custom) - Si plusieurs actives, tirage aleatoire a chaque photo - Preview dans le backoffice avec tirage aleatoire - Suppression des animations custom importees - Les animations custom se jouent en plein ecran avant la capture Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
import json
|
|
import os
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
RACINE = Path(__file__).resolve().parent.parent
|
|
CHEMIN_CONFIG = RACINE / "data" / "config.json"
|
|
CHEMIN_CONFIG_DEFAUT = RACINE / "data" / "config.defaut.json"
|
|
DOSSIER_PHOTOS = RACINE / "data" / "photos"
|
|
DOSSIER_EXPORTS = RACINE / "data" / "exports"
|
|
DOSSIER_OVERLAYS = RACINE / "frontend" / "assets" / "overlays"
|
|
DOSSIER_FONDS = RACINE / "frontend" / "assets" / "backgrounds"
|
|
DOSSIER_ANIMATIONS = RACINE / "frontend" / "assets" / "animations"
|
|
|
|
|
|
def charger_config() -> dict:
|
|
"""Charge la configuration depuis config.json."""
|
|
if not CHEMIN_CONFIG.exists():
|
|
if CHEMIN_CONFIG_DEFAUT.exists():
|
|
shutil.copy(CHEMIN_CONFIG_DEFAUT, CHEMIN_CONFIG)
|
|
else:
|
|
return {}
|
|
with open(CHEMIN_CONFIG, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
def sauvegarder_config(config: dict):
|
|
"""Sauvegarde la configuration dans config.json."""
|
|
CHEMIN_CONFIG.parent.mkdir(parents=True, exist_ok=True)
|
|
with open(CHEMIN_CONFIG, "w", encoding="utf-8") as f:
|
|
json.dump(config, f, ensure_ascii=False, indent=2)
|
|
|
|
|
|
def mettre_a_jour_config(modifications: dict) -> dict:
|
|
"""Met a jour la configuration avec les modifications fournies (merge profond)."""
|
|
config = charger_config()
|
|
_merge_profond(config, modifications)
|
|
sauvegarder_config(config)
|
|
return config
|
|
|
|
|
|
def _merge_profond(base: dict, modifications: dict):
|
|
"""Fusionne recursivement les modifications dans la base."""
|
|
for cle, valeur in modifications.items():
|
|
if cle in base and isinstance(base[cle], dict) and isinstance(valeur, dict):
|
|
_merge_profond(base[cle], valeur)
|
|
else:
|
|
base[cle] = valeur
|
|
|
|
|
|
# Initialisation des dossiers au chargement du module
|
|
for dossier in [DOSSIER_PHOTOS, DOSSIER_EXPORTS, DOSSIER_OVERLAYS, DOSSIER_FONDS, DOSSIER_ANIMATIONS]:
|
|
dossier.mkdir(parents=True, exist_ok=True)
|