mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-11 18:10:06 +08:00
feat(system): 添加后端初始化和健康检查功能
- 新增后端初始化对话框组件 - 实现后端健康检查和初始化逻辑 - 在 App 组件中集成后端初始化和健康检查 - 新增系统健康检查 API 和相关服务
This commit is contained in:
@@ -22,8 +22,8 @@ BASE_PROMPT = '''
|
||||
- 或者使用 `## 1. 内容` 的形式作为标题。
|
||||
|
||||
请确保以下格式 **不会出现误渲染**:
|
||||
❌ `1. **xxx**`
|
||||
✅ `1\. **xxx**` 或 `## 1. xxx`
|
||||
`1. **xxx**`
|
||||
`1\. **xxx**` 或 `## 1. xxx`
|
||||
|
||||
视频分段(格式:开始时间 - 内容):
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class UniversalGPT(GPT):
|
||||
}
|
||||
})
|
||||
|
||||
# ✅ 正确格式:整体包在一个 message 里,role + content array
|
||||
# 正确格式:整体包在一个 message 里,role + content array
|
||||
messages = [{
|
||||
"role": "user",
|
||||
"content": content
|
||||
|
||||
@@ -11,5 +11,5 @@ class AudioDownloadResult:
|
||||
platform: str # 平台,如 "bilibili"
|
||||
video_id: str # 唯一视频ID
|
||||
raw_info: dict # yt-dlp 的原始 info 字典
|
||||
video_path: Optional[str] = None # ✅ 新增字段:可选视频文件路径
|
||||
video_path: Optional[str] = None # 新增字段:可选视频文件路径
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from typing import Optional
|
||||
from app.utils.response import ResponseWrapper as R
|
||||
|
||||
from app.services.cookie_manager import CookieConfigManager
|
||||
from ffmpeg_helper import ensure_ffmpeg_or_raise
|
||||
|
||||
router = APIRouter()
|
||||
cookie_manager = CookieConfigManager()
|
||||
@@ -30,3 +31,11 @@ def update_cookie(data: CookieUpdateRequest):
|
||||
return R.success(
|
||||
|
||||
)
|
||||
|
||||
@router.get("/sys_health")
|
||||
async def sys_health():
|
||||
try:
|
||||
ensure_ffmpeg_or_raise()
|
||||
return R.success()
|
||||
except EnvironmentError:
|
||||
return R.error(msg="系统未安装 ffmpeg 请先进行安装")
|
||||
|
||||
@@ -238,7 +238,7 @@ async def image_proxy(request: Request, url: str):
|
||||
resp.aiter_bytes(),
|
||||
media_type=content_type,
|
||||
headers={
|
||||
"Cache-Control": "public, max-age=86400", # ✅ 缓存一天
|
||||
"Cache-Control": "public, max-age=86400", # 缓存一天
|
||||
"Content-Type": content_type,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ from app.services.provider import ProviderService
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# ✅ 新增 type 字段
|
||||
# 新增 type 字段
|
||||
class ProviderRequest(BaseModel):
|
||||
name: str
|
||||
api_key: str
|
||||
|
||||
@@ -79,13 +79,13 @@ class WhisperTranscriber(Transcriber):
|
||||
def is_cuda() -> bool:
|
||||
try:
|
||||
if is_cuda_available():
|
||||
print("✅ CUDA 可用,使用 GPU")
|
||||
print(" CUDA 可用,使用 GPU")
|
||||
return True
|
||||
elif is_torch_installed():
|
||||
print("⚠️ 只装了 torch,但没有 CUDA,用 CPU")
|
||||
return False
|
||||
else:
|
||||
print("❌ 还没有安装 torch,请先安装")
|
||||
print(" 还没有安装 torch,请先安装")
|
||||
return False
|
||||
|
||||
except ImportError:
|
||||
|
||||
@@ -31,7 +31,7 @@ def ensure_ffmpeg_or_raise():
|
||||
if not check_ffmpeg_exists():
|
||||
logger.error("未检测到 ffmpeg,请先安装后再使用本功能。")
|
||||
raise EnvironmentError(
|
||||
"❌ 未检测到 ffmpeg,请先安装后再使用本功能。\n"
|
||||
" 未检测到 ffmpeg,请先安装后再使用本功能。\n"
|
||||
"👉 下载地址:https://ffmpeg.org/download.html\n"
|
||||
"🪟 Windows 推荐:https://www.gyan.dev/ffmpeg/builds/\n"
|
||||
"💡 如果你已安装,请将其路径写入 `.env` 文件,例如:\n"
|
||||
|
||||
@@ -39,7 +39,6 @@ if not os.path.exists(out_dir):
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
register_handler()
|
||||
ensure_ffmpeg_or_raise()
|
||||
init_db()
|
||||
get_transcriber(transcriber_type=os.getenv("TRANSCRIBER_TYPE", "fast-whisper"))
|
||||
seed_default_providers()
|
||||
@@ -48,7 +47,7 @@ async def lifespan(app: FastAPI):
|
||||
app = create_app(lifespan=lifespan)
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["tauri://localhost"], # ✅ 加上 Tauri 的 origin
|
||||
allow_origins=["tauri://localhost"], # 加上 Tauri 的 origin
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
|
||||
Reference in New Issue
Block a user