新增 FastAPI 文件服务器核心模块(配置、鉴权、存储、心跳上报),新增 HTTP 路由接口(健康检查、文件上传/下载/删除、管理登录/密码修改/统计),新增 Vue3 管理页面源码;新增 MySQL 元数据存储支持,新增 PyMySQL 依赖;新增 .gitignore 忽略 IDE 与备份文件;新增文件服务器工具脚本;删除旧的 build/ 脚本与 exe 构建产物,优化 Electron 平台登录逻辑为纯接口模式,新增平台账号环境变量注入,优化试用期异常检查逻辑,拆分服务岗转正流程为独立脚本。
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""内网文件服务器入口(组装层)。
|
||
|
||
职责:lifespan 初始化存储(自动建表)+ 启动心跳上报,装配各领域路由。
|
||
- core/config.py 配置(.env)
|
||
- core/auth.py 鉴权(X-API-Token / 管理会话)
|
||
- core/store.py 存储(文件落盘 + MySQL 元数据,未配库时 JSON 兜底)
|
||
- core/heartbeat.py 中心机心跳上报
|
||
- apis/ 路由子包(meta / files / admin)
|
||
|
||
运行(cwd = desktop/,模块搜索根 = desktop/):
|
||
python -m fileserver.main
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
from contextlib import asynccontextmanager
|
||
|
||
from fastapi import FastAPI
|
||
|
||
from fileserver.core import config, store
|
||
from fileserver.core.heartbeat import start as start_heartbeat
|
||
from fileserver.apis import admin, files, meta
|
||
|
||
|
||
@asynccontextmanager
|
||
async def _lifespan(_app: FastAPI):
|
||
store.init() # 建数据目录 + DB 模式自动建表
|
||
start_heartbeat() # 中心机心跳上报(daemon 线程)
|
||
yield
|
||
|
||
|
||
app = FastAPI(title="37du 内网文件服务器", version=config.VERSION, lifespan=_lifespan)
|
||
app.include_router(meta.router)
|
||
app.include_router(files.router)
|
||
app.include_router(admin.router)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
import uvicorn
|
||
uvicorn.run(app, host="0.0.0.0", port=config.PORT)
|