Support auth for szh branch

This commit is contained in:
DingZQ
2025-06-17 22:01:24 +08:00
parent 4673ceb2b0
commit 058a517280

15
main.py
View File

@@ -31,6 +31,8 @@ import logging
import threading
import time
from logging.handlers import TimedRotatingFileHandler
from fastapi import FastAPI, APIRouter, Depends, HTTPException, status, Request
from fastapi.security import OAuth2PasswordBearer
JUNCTION = 0
RESERVOIR = 1
@@ -51,6 +53,19 @@ if not os.path.exists(inpDir):
if not os.path.exists(tmpDir):
os.mkdir(tmpDir)
# 全局依赖项
async def global_auth(request: Request):
# 白名单跳过
# if request.url.path in WHITE_LIST:
# return
# 验证
token = request.headers.get("Authorization")
if token != "expected_token":
raise HTTPException(status_code=401, detail="Invalid token")
# 全局依赖项
# app = FastAPI(dependencies=[Depends(global_auth)])
app = FastAPI()
# 将 Query的信息 序列号到 redis/json 默认不支持datetime需要自定义