File size: 1,123 Bytes
b37555b
b1d6576
8d3e422
8029647
86a264a
 
 
 
b37555b
86a264a
b37555b
 
86a264a
 
 
b37555b
86a264a
0dd16f5
 
 
b37555b
 
0dd16f5
b37555b
 
86a264a
b37555b
 
86a264a
b37555b
 
 
 
0dd16f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import APIRouter, HTTPException, Request, Depends
from config_provider import get_config, ServiceConfig
from service_config import ServiceConfig
import json

router = APIRouter()

@router.get("/get")
def get_config_values(config: ServiceConfig = Depends(get_config)):
    return {
        "work_mode": config.work_mode,
        "cloud_token": config.cloud_token
    }

@router.post("/update")
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"}