Spaces:
Paused
Paused
| from fastapi import APIRouter, HTTPException, Request, Depends | |
| from config_provider import get_config, ServiceConfig | |
| from service_config import ServiceConfig | |
| import json | |
| router = APIRouter() | |
| def get_config_values(config: ServiceConfig = Depends(get_config)): | |
| return { | |
| "work_mode": config.work_mode, | |
| "cloud_token": config.cloud_token | |
| } | |
| async def update_config(request: Request, config: ServiceConfig = Depends(get_config)): | |
| data = await request.json() | |
| work_mode = data.get("work_mode") | |
| cloud_token = data.get("cloud_token") | |
| if work_mode not in ["hfcloud", "cloud", "on-premise"]: | |
| raise HTTPException(status_code=400, detail="Invalid work mode") | |
| if (work_mode in ["hfcloud", "cloud"]) and not cloud_token: | |
| raise HTTPException(status_code=400, detail="Cloud token required for selected mode") | |
| config.work_mode = work_mode | |
| config.cloud_token = cloud_token | |
| with open(config.config_path, "w", encoding="utf-8") as f: | |
| json.dump(config, f, indent=2) | |
| return {"message": "Configuration updated"} | |