修复接口文档无限重定向问题

This commit is contained in:
ktianc 2023-04-09 15:51:42 +08:00
parent a3888ac144
commit 47b98e4043
7 changed files with 11 additions and 16 deletions

View File

@ -66,7 +66,7 @@ service.interceptors.response.use(
// 这个状态码是和后端约定好的 // 这个状态码是和后端约定好的
const code = response.data.code || unauthorized_code const code = response.data.code || unauthorized_code
const message = response.data.message || '后端接口无返回内容' const message = response.data.message || '后端接口无返回内容'
const refresh = response.headers.refresh const refresh = response.headers['if-refresh']
if (response.config.responseType === 'blob') { if (response.config.responseType === 'blob') {
// 如果是文件流,直接过 // 如果是文件流,直接过

View File

@ -11,7 +11,7 @@ from fastapi.security import OAuth2PasswordBearer
""" """
系统版本 系统版本
""" """
VERSION = "1.7.3" VERSION = "1.7.4"
"""安全警告: 不要在生产中打开调试运行!""" """安全警告: 不要在生产中打开调试运行!"""
DEBUG = True DEBUG = True

View File

@ -52,9 +52,9 @@ class AuthValidation:
# print("当前时间", buffer_time, datetime.fromtimestamp(buffer_time)) # print("当前时间", buffer_time, datetime.fromtimestamp(buffer_time))
# print("剩余时间", exp - buffer_time) # print("剩余时间", exp - buffer_time)
if buffer_time >= exp: if buffer_time >= exp:
request.scope["refresh"] = 1 request.scope["if-refresh"] = 1
else: else:
request.scope["refresh"] = 0 request.scope["if-refresh"] = 0
except jwt.exceptions.InvalidSignatureError: except jwt.exceptions.InvalidSignatureError:
raise CustomException(msg="无效认证,请您重新登录", code=cls.error_code) raise CustomException(msg="无效认证,请您重新登录", code=cls.error_code)
except jwt.exceptions.ExpiredSignatureError: except jwt.exceptions.ExpiredSignatureError:

View File

@ -67,10 +67,7 @@ async def put_dict_types(data_id: int, data: schemas.DictType, auth: Auth = Depe
@app.get("/dict/types/{data_id}/", summary="获取字典类型详细") @app.get("/dict/types/{data_id}/", summary="获取字典类型详细")
async def get_dict_type(data_id: int, auth: Auth = Depends(AllUserAuth())): async def get_dict_type(data_id: int, auth: Auth = Depends(AllUserAuth())):
schema = schemas.DictTypeSimpleOut schema = schemas.DictTypeSimpleOut
return SuccessResponse( return SuccessResponse(await crud.DictTypeDal(auth.db).get_data(data_id, None, v_schema=schema))
await crud.DictTypeDal(auth.db).get_data(data_id, None, v_schema=schema),
refresh=auth.refresh
)
########################################################### ###########################################################
@ -104,10 +101,7 @@ async def put_dict_details(data_id: int, data: schemas.DictDetails, auth: Auth =
@app.get("/dict/details/{data_id}/", summary="获取字典元素详情") @app.get("/dict/details/{data_id}/", summary="获取字典元素详情")
async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())): async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())):
schema = schemas.DictDetailsSimpleOut schema = schemas.DictDetailsSimpleOut
return SuccessResponse( return SuccessResponse(await crud.DictDetailsDal(auth.db).get_data(data_id, None, v_schema=schema))
await crud.DictDetailsDal(auth.db).get_data(data_id, None, v_schema=schema),
refresh=auth.refresh
)
########################################################### ###########################################################

View File

@ -144,6 +144,6 @@ def register_jwt_refresh_middleware(app: FastAPI):
@app.middleware("http") @app.middleware("http")
async def jwt_refresh_middleware(request: Request, call_next): async def jwt_refresh_middleware(request: Request, call_next):
response = await call_next(request) response = await call_next(request)
refresh = request.scope.get('refresh', 0) refresh = request.scope.get('if-refresh', 0)
response.headers["refresh"] = str(refresh) response.headers["if-refresh"] = str(refresh)
return response return response

View File

@ -53,7 +53,8 @@ def create_app():
allow_origins=settings.ALLOW_ORIGINS, allow_origins=settings.ALLOW_ORIGINS,
allow_credentials=settings.ALLOW_CREDENTIALS, allow_credentials=settings.ALLOW_CREDENTIALS,
allow_methods=settings.ALLOW_METHODS, allow_methods=settings.ALLOW_METHODS,
allow_headers=settings.ALLOW_HEADERS) allow_headers=settings.ALLOW_HEADERS
)
# 挂在静态目录 # 挂在静态目录
if settings.STATIC_ENABLE: if settings.STATIC_ENABLE:
app.mount(settings.STATIC_URL, app=StaticFiles(directory=settings.STATIC_ROOT)) app.mount(settings.STATIC_URL, app=StaticFiles(directory=settings.STATIC_ROOT))

View File

@ -42,7 +42,7 @@ http.interceptors.response.use(
// 获取错误信息 // 获取错误信息
const msg = res.data.message || errorCode[code] || errorCode['default'] const msg = res.data.message || errorCode[code] || errorCode['default']
// 是否刷新token // 是否刷新token
const refresh = res.header.refresh const refresh = res.header['if-refresh']
if (code === 500) { if (code === 500) {
toast(msg) toast(msg)
return Promise.reject(new Error(msg)) return Promise.reject(new Error(msg))