refactor: 完成项目目录重构与代码迁移

本次提交完成了整体项目的目录梳理与代码迁移:
1.  将根级controlplane、webhost等目录的代码迁移至desktop/对应子目录,统一桌面端架构
2.  移动并整理了插件目录结构,将插件统一放入根级plugins/
3.  调整了前端项目的路径与配置,统一前后端开发构建流程
4.  清理了废弃的旧版app/目录与冗余的构建中间文件
5.  更新了.gitignore与README.md,适配新的项目结构
This commit is contained in:
2026-09-14 17:46:09 +08:00
parent a1a06504a5
commit 0ab43d0ed8
131 changed files with 4071 additions and 38034 deletions
+91
View File
@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-
"""内网插件控制面(中心机)入口(组装层)。
业务逻辑已按领域拆到 sibling 模块,本文件仅承担:lifespan 初始化、创建 app、
装配各领域路由、挂载前端产物、uvicorn 启动。
- config.py 配置/路径/密钥 - db.py 数据层(建表/种子/审计)
- crypto.py 口令哈希/Ed25519 - auth.py 鉴权(凭证/票据/防爆破/云端会话)
- dingtalk.py 钉钉官方接口 - pkgutil.py 插件包校验/解析/版本
- schemas.py 请求体模型 - apis/ 路由子包(meta/plugins/auth/dingtalk/admin)
DB:controlplane.db(同目录)。包文件:packages/。可选:CONTROLPLANE_TOKEN 非空时客户端须带
X-API-Token 请求头。
运行(本地 .venv,需在 desktop/ 目录下执行,模块搜索根 = desktop/):
python -m controlplane.app # 首次自动建表 + 种子 + 生成示例包
uvicorn controlplane.app:app --port 8800
"""
from __future__ import annotations
import os
import sys
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from controlplane import config
from controlplane.core.db import _init_db, _seed
from controlplane.apis import admin as api_admin
from controlplane.apis import auth as api_auth
from controlplane.apis import dingtalk as api_dingtalk
from controlplane.apis import meta as api_meta
from controlplane.apis import plugins as api_plugins
@asynccontextmanager
async def lifespan(app: FastAPI):
_init_db()
_seed()
yield
app = FastAPI(title="37du 内网插件控制面", lifespan=lifespan)
app.add_middleware(CORSMiddleware, allow_origins=["*"],
allow_methods=["*"], allow_headers=["*"])
app.include_router(api_meta.router)
app.include_router(api_plugins.router)
app.include_router(api_auth.router)
app.include_router(api_dingtalk.router)
app.include_router(api_admin.router)
# ==================== 挂载控制面前端产物 ====================
# 源码模式 => config.DIST(controlplane/frontend/dist);exe 模式 => _MEIPASS/frontend/dist(打进 exe)
if config.DIST.is_dir():
app.mount("/", StaticFiles(directory=str(config.DIST), html=True), name="web")
if __name__ == "__main__":
import uvicorn
# PyInstaller --noconsole 下 sys.stdout/stderr 可能为 None,
# uvicorn 默认 DefaultFormatter 会调用 isatty() 导致启动崩溃,故自定义日志配置绕开颜色检测。
LOG_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"},
"access": {"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"},
},
"handlers": {
"default": {"class": "logging.StreamHandler", "formatter": "default"},
"access": {"class": "logging.StreamHandler", "formatter": "access"},
},
"loggers": {
"uvicorn": {"handlers": ["default"], "level": "INFO", "propagate": False},
"uvicorn.error": {"handlers": ["default"], "level": "INFO", "propagate": False},
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False},
},
}
if getattr(sys, "frozen", False):
if sys.stdout is None:
sys.stdout = open(os.devnull, "w")
if sys.stderr is None:
sys.stderr = open(os.devnull, "w")
print(f"[controlplane] http://0.0.0.0:{config.CONTROLPLANE_PORT} sqlite={config.DB_PATH.name}")
uvicorn.run(app, host="0.0.0.0", port=config.CONTROLPLANE_PORT,
log_config=LOG_CONFIG, log_level="info")