52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import uvicorn
|
|
import os
|
|
import json
|
|
from fastapi import FastAPI
|
|
from pathlib import Path
|
|
from models.schemas.system import InitStatusResponse, InitConfigRequest
|
|
from core.config import load_init_config, save_init_config
|
|
|
|
|
|
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 = await 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):
|
|
init_config = await load_init_config()
|
|
if init_config.get('is_init'):
|
|
return InitStatusResponse(data=True)
|
|
init_config["db_type"] = request.db_type
|
|
if request.db_type == "mysql":
|
|
pass
|
|
init_config["is_init"] = True
|
|
await save_init_config(init_config)
|
|
return InitStatusResponse(data=True)
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8080, reload=True)
|