项目基础模块代码

This commit is contained in:
2025-02-19 16:57:49 +08:00
parent 31302bcd17
commit bed123c532
14 changed files with 159 additions and 57 deletions

View File

@ -6,7 +6,6 @@ from app.common import reponse_code as rc
from app.common import jwt_check as jc
class TokenMiddleware(BaseHTTPMiddleware):
def __init__(self, app):
@ -21,7 +20,7 @@ class TokenMiddleware(BaseHTTPMiddleware):
"""
token = request.headers.get('Authorization')
path = request.url.path
if '/login' in path:
if check_green(path):
response = await call_next(request)
return response
if not token:
@ -30,4 +29,15 @@ class TokenMiddleware(BaseHTTPMiddleware):
jc.check_token(token)
return await call_next(request)
except PyJWTError as error:
print(error)
return rc.response_code_view(status.HTTP_401_UNAUTHORIZED, "Token错误或失效请重新验证")
green = ['/login', '/view_img']
def check_green(s: str):
for url in green:
if url in s:
return True
return False