From d99b278d24529addf18946bdf47bc69d454814d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A6=82=E5=A8=81?= Date: Thu, 21 Aug 2025 23:32:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 38 ++++++++++++++++++++ backend/.python-version | 1 + backend/app/config/init.json | 11 ++++++ backend/app/main.py | 52 ++++++++++++++++++++++++++++ backend/app/models/schemas/system.py | 20 +++++++++++ backend/requirements.txt | 2 ++ 6 files changed, 124 insertions(+) create mode 100644 .gitignore create mode 100644 backend/.python-version create mode 100644 backend/app/config/init.json create mode 100644 backend/app/main.py create mode 100644 backend/app/models/schemas/system.py create mode 100644 backend/requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6d299 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# ---- 通用 ---- +.DS_Store +*.log +*.tmp +*.swp +__pycache__/ +*.py[cod] +.env +venv/ +.idea/ +.vscode/ + +# ---- Python (backend) ---- +backend/__pycache__/ +backend/.mypy_cache/ +backend/.pytest_cache/ +backend/.ruff_cache/ +*.sqlite3 + +# 虚拟环境 +backend/venv/ +.env/ + +# ---- Node.js / React (frontend) ---- +frontend/node_modules/ +frontend/dist/ +frontend/.vite/ +frontend/.eslintcache + +# 打包产物 +*.tgz + +# ---- Docker ---- +*.pid +*.seed +*.pid.lock +docker-compose.override.yml + diff --git a/backend/.python-version b/backend/.python-version new file mode 100644 index 0000000..4eba2a6 --- /dev/null +++ b/backend/.python-version @@ -0,0 +1 @@ +3.13.0 diff --git a/backend/app/config/init.json b/backend/app/config/init.json new file mode 100644 index 0000000..4266856 --- /dev/null +++ b/backend/app/config/init.json @@ -0,0 +1,11 @@ +{ + "is_init": false, + "db_type": "sqlite", + "mysql": { + "host": "", + "port": "", + "user": "", + "password": "", + "db_name": "" + } +} \ No newline at end of file diff --git a/backend/app/main.py b/backend/app/main.py new file mode 100644 index 0000000..da0f2d7 --- /dev/null +++ b/backend/app/main.py @@ -0,0 +1,52 @@ +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) diff --git a/backend/app/models/schemas/system.py b/backend/app/models/schemas/system.py new file mode 100644 index 0000000..99b942d --- /dev/null +++ b/backend/app/models/schemas/system.py @@ -0,0 +1,20 @@ +from pydantic import BaseModel + + +class BaseResponse(BaseModel): + success: bool = True + message: str | None = None + + +class InitConfigRequest(BaseModel): + db_type: str + db_host: str | None + db_port: str | None + db_user: str | None + db_password: str | None + db_name: str | None + admin_password: str + + +class InitStatusResponse(BaseResponse): + data: bool = False diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..dced152 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,2 @@ +fastapi==0.116.1 +uvicorn==0.35,0 \ No newline at end of file