From 058a5172806d6305d95420ae93b6420ef5a5634c Mon Sep 17 00:00:00 2001 From: DingZQ Date: Tue, 17 Jun 2025 22:01:24 +0800 Subject: [PATCH] Support auth for szh branch --- main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.py b/main.py index 1281121..1d3f82c 100644 --- a/main.py +++ b/main.py @@ -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,需要自定义