# app/routes/config.py """ Маршруты API для управления конфигурацией """ from fastapi import APIRouter, HTTPException from pathlib import Path import json router = APIRouter() CONFIG_PATH = Path(__file__).parent.parent.parent / "config.json" @router.get("/") async def get_config(): """Получение текущей конфигурации""" try: if CONFIG_PATH.exists(): with open(CONFIG_PATH, 'r', encoding='utf-8') as f: return json.load(f) return {"message": "Config file not found"} except Exception as e: raise HTTPException(status_code=500, detail=f"Error reading config: {str(e)}") @router.put("/") async def update_config(config_data: dict): """Обновление конфигурации""" try: with open(CONFIG_PATH, 'w', encoding='utf-8') as f: json.dump(config_data, f, indent=4, ensure_ascii=False) return {"message": "Configuration updated successfully"} except Exception as e: raise HTTPException(status_code=500, detail=f"Error saving config: {str(e)}")