This commit is contained in:
2025-06-09 00:18:57 +08:00
parent e3dbe8a7d3
commit 8226a78482
10 changed files with 196 additions and 92 deletions
+2 -4
View File
@@ -2,10 +2,8 @@ import base64
import hmac
import json
import time
from typing import Optional
from core.character.adventure import get_adv_info
from core.basic.character import Character
from fastapi import Header, Request
from fastapi import Header
from api.core.exception import ResponseException
@@ -67,7 +65,7 @@ def deleteToken(token, redis, env):
return token
def uid(access_uid: Optional[str] = Header(None)):
def uid(access_uid: str | None = Header(None)):
try:
return int(access_uid)
except Exception:
+1 -1
View File
@@ -1,7 +1,7 @@
import gzip
from fastapi import Request, APIRouter, FastAPI
from fastapi.responses import Response
from typing import Callable
from collections.abc import Callable
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.routing import APIRoute
+1 -1
View File
@@ -10,7 +10,7 @@ def get_redis_info(redis, key, fun,without_gzip=False):
info = json.loads(redis.get(key))
else:
info = json.loads(gzip_unzip(redis.get(key)))
except Exception as ex:
except Exception:
info = None
if info is None:
info = fun()
+7 -7
View File
@@ -1,20 +1,20 @@
import base64
import json
from typing import Generic, TypeVar
from pydantic import Field
from pydantic.generics import GenericModel
import gzip # 导入 gzip 模块
from io import BytesIO # 从 io 模块导入 BytesIO 类
T = TypeVar('T')
class Return(GenericModel, Generic[T]):
code: int = 200
message: str = ''
data: T | dict | str = None
code: int = Field(..., description='响应状态码')
"""响应状态码"""
message: str = Field(..., description='响应消息')
"""响应消息"""
data: T = Field(..., description='响应数据')
"""响应数据"""
# 定义一个函数,将字符串压缩为 gzip 格式,并进行 base64 编码后返回结果
def gzip_str(to_gzip: str) -> str: