Spaces:
Running
Running
Update project_controller.py
Browse files- project_controller.py +42 -2
project_controller.py
CHANGED
@@ -1,10 +1,14 @@
|
|
1 |
from fastapi import APIRouter, Request, HTTPException
|
2 |
from service_config import ServiceConfig
|
|
|
3 |
|
4 |
router = APIRouter()
|
5 |
service_config = ServiceConfig()
|
6 |
service_config.load()
|
7 |
|
|
|
|
|
|
|
8 |
@router.post("/add")
|
9 |
async def add_project(request: Request):
|
10 |
data = await request.json()
|
@@ -16,21 +20,49 @@ async def add_project(request: Request):
|
|
16 |
|
17 |
service_config.projects[project_name] = {
|
18 |
"enabled": False,
|
19 |
-
"versions": []
|
|
|
20 |
}
|
21 |
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
22 |
import json
|
23 |
json.dump(service_config, f, indent=2)
|
24 |
return {"message": f"Project {project_name} added"}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
@router.post("/publish")
|
27 |
async def publish_project(request: Request):
|
28 |
data = await request.json()
|
29 |
project_name = data.get("project_name")
|
|
|
|
|
30 |
project = service_config.projects.get(project_name)
|
31 |
if not project:
|
32 |
raise HTTPException(status_code=404, detail="Project not found")
|
33 |
|
|
|
|
|
|
|
34 |
latest_version = project["versions"][-1] if project["versions"] else None
|
35 |
if not latest_version:
|
36 |
raise HTTPException(status_code=400, detail="No version exists to publish")
|
@@ -41,4 +73,12 @@ async def publish_project(request: Request):
|
|
41 |
if llm.get("use_fine_tune") and not llm.get("fine_tune_zip"):
|
42 |
raise HTTPException(status_code=400, detail="fine_tune_zip is required when use_fine_tune is true")
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import APIRouter, Request, HTTPException
|
2 |
from service_config import ServiceConfig
|
3 |
+
import datetime
|
4 |
|
5 |
router = APIRouter()
|
6 |
service_config = ServiceConfig()
|
7 |
service_config.load()
|
8 |
|
9 |
+
def get_utc_now():
|
10 |
+
return datetime.datetime.utcnow().isoformat()
|
11 |
+
|
12 |
@router.post("/add")
|
13 |
async def add_project(request: Request):
|
14 |
data = await request.json()
|
|
|
20 |
|
21 |
service_config.projects[project_name] = {
|
22 |
"enabled": False,
|
23 |
+
"versions": [],
|
24 |
+
"last_updated": get_utc_now()
|
25 |
}
|
26 |
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
27 |
import json
|
28 |
json.dump(service_config, f, indent=2)
|
29 |
return {"message": f"Project {project_name} added"}
|
30 |
|
31 |
+
@router.post("/update")
|
32 |
+
async def update_project(request: Request):
|
33 |
+
data = await request.json()
|
34 |
+
project_name = data.get("project_name")
|
35 |
+
client_last_updated = data.get("client_last_updated")
|
36 |
+
|
37 |
+
project = service_config.projects.get(project_name)
|
38 |
+
if not project:
|
39 |
+
raise HTTPException(status_code=404, detail="Project not found")
|
40 |
+
|
41 |
+
if project["last_updated"] != client_last_updated:
|
42 |
+
raise HTTPException(status_code=409, detail="This record has been updated by another user. Please reload.")
|
43 |
+
|
44 |
+
# Buraya update işlemleri eklenir (örneğin versiyon ekleme vb.)
|
45 |
+
# Örnek: project['enabled'] = data.get('enabled', project['enabled'])
|
46 |
+
|
47 |
+
project["last_updated"] = get_utc_now()
|
48 |
+
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
49 |
+
import json
|
50 |
+
json.dump(service_config, f, indent=2)
|
51 |
+
return {"message": f"Project {project_name} updated"}
|
52 |
+
|
53 |
@router.post("/publish")
|
54 |
async def publish_project(request: Request):
|
55 |
data = await request.json()
|
56 |
project_name = data.get("project_name")
|
57 |
+
client_last_updated = data.get("client_last_updated")
|
58 |
+
|
59 |
project = service_config.projects.get(project_name)
|
60 |
if not project:
|
61 |
raise HTTPException(status_code=404, detail="Project not found")
|
62 |
|
63 |
+
if project["last_updated"] != client_last_updated:
|
64 |
+
raise HTTPException(status_code=409, detail="This record has been updated by another user. Please reload.")
|
65 |
+
|
66 |
latest_version = project["versions"][-1] if project["versions"] else None
|
67 |
if not latest_version:
|
68 |
raise HTTPException(status_code=400, detail="No version exists to publish")
|
|
|
73 |
if llm.get("use_fine_tune") and not llm.get("fine_tune_zip"):
|
74 |
raise HTTPException(status_code=400, detail="fine_tune_zip is required when use_fine_tune is true")
|
75 |
|
76 |
+
latest_version["published"] = True
|
77 |
+
latest_version["last_updated"] = get_utc_now()
|
78 |
+
project["last_updated"] = get_utc_now()
|
79 |
+
|
80 |
+
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
81 |
+
import json
|
82 |
+
json.dump(service_config, f, indent=2)
|
83 |
+
|
84 |
+
return {"message": f"Project {project_name} version published"}
|