Spaces:
Building
Building
Create config_controller.py
Browse files- config_controller.py +29 -0
config_controller.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import APIRouter, Request
|
2 |
+
from service_config import ServiceConfig
|
3 |
+
|
4 |
+
router = APIRouter()
|
5 |
+
service_config = ServiceConfig()
|
6 |
+
service_config.load()
|
7 |
+
|
8 |
+
@router.get("/get")
|
9 |
+
def get_config():
|
10 |
+
return {
|
11 |
+
"work_mode": service_config.work_mode,
|
12 |
+
"cloud_token": service_config.cloud_token,
|
13 |
+
"spark_endpoint": service_config.spark_endpoint,
|
14 |
+
"last_version_number": service_config.last_version_number
|
15 |
+
}
|
16 |
+
|
17 |
+
@router.post("/update")
|
18 |
+
async def update_config(request: Request):
|
19 |
+
data = await request.json()
|
20 |
+
service_config.work_mode = data.get("work_mode", service_config.work_mode)
|
21 |
+
service_config.cloud_token = data.get("cloud_token", service_config.cloud_token)
|
22 |
+
service_config.spark_endpoint = data.get("spark_endpoint", service_config.spark_endpoint)
|
23 |
+
|
24 |
+
# Config'i kaydet
|
25 |
+
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
26 |
+
import json
|
27 |
+
json.dump(service_config, f, indent=2)
|
28 |
+
|
29 |
+
return {"message": "Configuration updated successfully"}
|