mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-07 07:22:43 +08:00
### 性能优化 - 后端任务执行从串行锁改为 ThreadPoolExecutor 并发执行(默认3线程) - 添加 GZipMiddleware 响应压缩 + Nginx gzip 配置 - 数据库连接池参数优化(pool_size=10, max_overflow=20) - 视频帧提取并行化(ThreadPoolExecutor) - LLM 重试配置缓存到实例,避免每次请求读 env var - 前端路由级代码拆分(React.lazy + Suspense) - Vite manualChunks 拆分 markdown/markmap/vendor - MarkdownViewer 用 React.memo + useMemo 减少不必要渲染 - NoteHistory Fuse.js 实例 useMemo 缓存 - useTaskPolling 无待处理任务时跳过轮询 - 移除 antd 依赖(NoteForm Alert、modelForm Tag),改用 shadcn/ui ### 前端转写器配置(新功能) - 新增 TranscriberConfigManager(JSON 文件存储,替代环境变量) - 新增 GET/POST /transcriber_config API 端点 - 新增 GET /transcriber_models_status 模型下载状态查询 - 新增 POST /transcriber_download 后台模型下载触发 - 前端转写器设置页面:引擎选择、模型大小选择、模型下载管理 - deploy_status 端点同步从配置文件读取 ### Bug 修复 - 修复任务进行中切换页面后进度丢失:Home.tsx status 派生逻辑补全中间状态 - 修复 MLX Whisper 静默回退 fast-whisper:移除环境变量门控,macOS 下自动尝试导入 - MLX Whisper 不可用时抛出 RuntimeError 而非静默回退 - 前端展示 MLX Whisper 可用性状态,不可用时禁用保存 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
import os
|
||
from contextlib import asynccontextmanager
|
||
|
||
import uvicorn
|
||
from fastapi import FastAPI
|
||
from starlette.middleware.cors import CORSMiddleware
|
||
from starlette.middleware.gzip import GZipMiddleware
|
||
from starlette.staticfiles import StaticFiles
|
||
from dotenv import load_dotenv
|
||
|
||
from app.db.init_db import init_db
|
||
from app.db.provider_dao import seed_default_providers
|
||
from app.exceptions.exception_handlers import register_exception_handlers
|
||
# from app.db.model_dao import init_model_table
|
||
# from app.db.provider_dao import init_provider_table
|
||
from app.utils.logger import get_logger
|
||
from app import create_app
|
||
from app.services.transcriber_config_manager import TranscriberConfigManager
|
||
from events import register_handler
|
||
from ffmpeg_helper import ensure_ffmpeg_or_raise
|
||
|
||
logger = get_logger(__name__)
|
||
load_dotenv()
|
||
|
||
# 读取 .env 中的路径
|
||
static_path = os.getenv('STATIC', '/static')
|
||
out_dir = os.getenv('OUT_DIR', './static/screenshots')
|
||
|
||
# 自动创建本地目录(static 和 static/screenshots)
|
||
static_dir = "static"
|
||
uploads_dir = "uploads"
|
||
if not os.path.exists(static_dir):
|
||
os.makedirs(static_dir)
|
||
if not os.path.exists(uploads_dir):
|
||
os.makedirs(uploads_dir)
|
||
|
||
if not os.path.exists(out_dir):
|
||
os.makedirs(out_dir)
|
||
|
||
@asynccontextmanager
|
||
async def lifespan(app: FastAPI):
|
||
register_handler()
|
||
init_db()
|
||
# 转写器不再在启动时强制初始化,而是在首次生成笔记时按需创建
|
||
# 如果配置了不可用的类型(如 mlx-whisper 未安装),会在使用时报错而非静默回退
|
||
_cfg = TranscriberConfigManager().get_config()
|
||
logger.info(f"当前转写器配置: type={_cfg['transcriber_type']}, model_size={_cfg['whisper_model_size']}")
|
||
seed_default_providers()
|
||
yield
|
||
|
||
app = create_app(lifespan=lifespan)
|
||
origins = [
|
||
"http://localhost",
|
||
"http://127.0.0.1",
|
||
"http://tauri.localhost",
|
||
]
|
||
|
||
app.add_middleware(
|
||
CORSMiddleware,
|
||
allow_origins=origins, # 加上 Tauri 的 origin
|
||
allow_credentials=True,
|
||
allow_methods=["*"],
|
||
allow_headers=["*"],
|
||
)
|
||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||
register_exception_handlers(app)
|
||
app.mount(static_path, StaticFiles(directory=static_dir), name="static")
|
||
app.mount("/uploads", StaticFiles(directory=uploads_dir), name="uploads")
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__ == "__main__":
|
||
port = int(os.getenv("BACKEND_PORT", 8483))
|
||
host = os.getenv("BACKEND_HOST", "0.0.0.0")
|
||
logger.info(f"Starting server on {host}:{port}")
|
||
uvicorn.run(app, host=host, port=port, reload=False) |