File size: 1,156 Bytes
0dd16f5
86a264a
8029647
86a264a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0dd16f5
 
 
 
 
 
 
 
 
 
86a264a
 
 
 
 
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
36
37
from fastapi import APIRouter, Request, HTTPException
from service_config import ServiceConfig
import json

router = APIRouter()
service_config = ServiceConfig()
service_config.load()

@router.get("/get")
def get_config():
    return {
        "work_mode": service_config.work_mode,
        "cloud_token": service_config.cloud_token,
        "spark_endpoint": service_config.spark_endpoint,
        "last_version_number": service_config.last_version_number
    }

@router.post("/update")
async def update_config(request: Request):
    data = await request.json()
    work_mode = data.get("work_mode")
    cloud_token = data.get("cloud_token")
    spark_endpoint = data.get("spark_endpoint")

    if not work_mode or not spark_endpoint:
        raise HTTPException(status_code=400, detail="work_mode and spark_endpoint cannot be empty")

    service_config.work_mode = work_mode
    service_config.cloud_token = cloud_token
    service_config.spark_endpoint = spark_endpoint

    with open(service_config.config_path, "w", encoding="utf-8") as f:
        json.dump(service_config, f, indent=2)

    return {"message": "Configuration updated successfully"}