- 音频/视频转双语(英/中)SRT 字幕,Docker 容器化,CPU 开发/GPU 生产同一份代码 - faster-whisper ASR(词级时间戳) + 断句时间戳重算 + NLLB 翻译(模型不共驻) - 分片上传(断点续传) + SQLite 持久化 + 主页/历史/日志页面 - 历史页文件名搜索;缓存定时清理(默认保留7天,可配置) - 双 Dockerfile(cpu/gpu) + setup/start/stop 脚本
28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
"""/docs Basic Auth:对齐 server/security.py。明文密码,常量时间比较。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import secrets
|
||
|
||
from fastapi import Depends, HTTPException, status
|
||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||
|
||
from .config import get_settings
|
||
|
||
security = HTTPBasic()
|
||
|
||
|
||
def require_docs_auth(credentials: HTTPBasicCredentials = Depends(security)) -> str:
|
||
s = get_settings()
|
||
if not s.docs.enabled or not s.docs.password:
|
||
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="docs disabled")
|
||
ok_user = secrets.compare_digest(credentials.username.encode(), s.docs.username.encode())
|
||
ok_pass = secrets.compare_digest(credentials.password.encode(), s.docs.password.encode())
|
||
if not (ok_user and ok_pass):
|
||
raise HTTPException(
|
||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||
detail="invalid credentials",
|
||
headers={"WWW-Authenticate": f'Basic realm="{s.docs.realm}"'},
|
||
)
|
||
return credentials.username
|