53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
import uvicorn
|
|
import os
|
|
import json
|
|
from fastapi import FastAPI
|
|
from pathlib import Path
|
|
from models.schemas.system import InitStatusResponse, InitConfigRequest
|
|
|
|
|
|
# 响应类型
|
|
|
|
|
|
def load_init_config():
|
|
"""读取配置文件"""
|
|
config_path = Path(__file__).parent / "config" / "init.json"
|
|
with open(config_path, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
def create_app():
|
|
app = FastAPI(title="Workflow API", version="1.0.0")
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "hello"}
|
|
|
|
@app.get(
|
|
"/check_init",
|
|
tags=["System"],
|
|
description="系统是否初始化",
|
|
response_model=InitStatusResponse,
|
|
)
|
|
async def check_init():
|
|
init_config = load_init_config()
|
|
is_init = init_config.get("is_init")
|
|
return InitStatusResponse(data=is_init)
|
|
|
|
@app.post(
|
|
"/init_system",
|
|
tags=["System"],
|
|
description="系统初始化",
|
|
response_model=InitStatusResponse,
|
|
)
|
|
async def init_system(request: InitConfigRequest):
|
|
return InitStatusResponse()
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8080, reload=True)
|