mirror of
https://github.com/wangdage12/Snap.Server.git
synced 2026-02-17 08:52:10 +08:00
添加类型注释、修复抽卡id问题
This commit is contained in:
@@ -2,6 +2,12 @@ from app.extensions import client, logger
|
||||
from app.config import Config
|
||||
|
||||
def get_announcements(request_data: list):
|
||||
"""
|
||||
获取公告列表,过滤掉用户已关闭的公告
|
||||
|
||||
:param request_data: 用户已关闭的公告ID列表
|
||||
:type request_data: list
|
||||
"""
|
||||
if Config.ISTEST_MODE:
|
||||
return []
|
||||
# 记录请求体到日志,请求体中是用户已关闭的公告ID列表
|
||||
|
||||
@@ -12,7 +12,7 @@ import SendEmailTool
|
||||
import re
|
||||
import base64
|
||||
|
||||
def decrypt_data(encrypted_data):
|
||||
def decrypt_data(encrypted_data: str) -> str:
|
||||
"""使用RSA私钥解密数据"""
|
||||
try:
|
||||
private_key_file = config_loader.RSA_PRIVATE_KEY_FILE
|
||||
@@ -26,7 +26,7 @@ def decrypt_data(encrypted_data):
|
||||
raise
|
||||
|
||||
|
||||
def send_verification_email(email, code, ACTION_NAME="注册", EXPIRE_MINUTES=None):
|
||||
def send_verification_email(email: str, code: str, ACTION_NAME="注册", EXPIRE_MINUTES=None) -> bool:
|
||||
"""发送验证码邮件,目前只有注册场景,后续再扩展其他场景"""
|
||||
try:
|
||||
subject = Config.EMAIL_SUBJECT
|
||||
@@ -151,7 +151,7 @@ def send_verification_email(email, code, ACTION_NAME="注册", EXPIRE_MINUTES=No
|
||||
return False
|
||||
|
||||
|
||||
def verify_user_credentials(email, password):
|
||||
def verify_user_credentials(email: str, password: str) -> dict | None:
|
||||
"""验证用户凭据"""
|
||||
user = client.ht_server.users.find_one({"email": email})
|
||||
|
||||
@@ -161,7 +161,7 @@ def verify_user_credentials(email, password):
|
||||
return user
|
||||
|
||||
|
||||
def create_user_account(email, password):
|
||||
def create_user_account(email: str, password: str) -> dict | None:
|
||||
"""创建新用户账户"""
|
||||
# 检查用户是否已存在
|
||||
existing_user = client.ht_server.users.find_one({"email": email})
|
||||
@@ -191,7 +191,7 @@ def create_user_account(email, password):
|
||||
return new_user
|
||||
|
||||
|
||||
def get_user_by_id(user_id):
|
||||
def get_user_by_id(user_id: str) -> dict | None:
|
||||
"""根据ID获取用户信息"""
|
||||
try:
|
||||
user = client.ht_server.users.find_one({"_id": ObjectId(user_id)})
|
||||
@@ -203,7 +203,7 @@ def get_user_by_id(user_id):
|
||||
return None
|
||||
|
||||
|
||||
def get_users_with_search(query_text=""):
|
||||
def get_users_with_search(query_text="") -> list:
|
||||
"""获取用户列表,支持搜索"""
|
||||
import re
|
||||
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
from app.extensions import client, logger
|
||||
|
||||
"""
|
||||
注意!记录中有两种类型,GachaType和QueryType(uigf_gacha_type),GachaType多了一个400类型,其实就是QueryType的301类型,客户端传的end_ids是按QueryType来的,如果按照GachaType来筛选会多出400类型的记录
|
||||
映射关系
|
||||
|
||||
| `uigf_gacha_type` | `gacha_type` |
|
||||
|-------------------|----------------|
|
||||
| `100` | `100` |
|
||||
| `200` | `200` |
|
||||
| `301` | `301` or `400` |
|
||||
| `302` | `302` |
|
||||
| `500` | `500` |
|
||||
"""
|
||||
|
||||
def get_gacha_log_entries(user_id):
|
||||
"""获取用户的祈愿记录条目列表"""
|
||||
@@ -41,6 +53,9 @@ def get_gacha_log_end_ids(user_id, uid):
|
||||
if gacha_type in end_ids:
|
||||
end_ids[gacha_type] = max(end_ids[gacha_type], item_id)
|
||||
|
||||
# 400类型对应301类型
|
||||
end_ids["400"] = end_ids["301"]
|
||||
|
||||
return end_ids
|
||||
|
||||
|
||||
@@ -82,6 +97,11 @@ def retrieve_gacha_log(user_id, uid, end_ids):
|
||||
|
||||
# 筛选出比end_ids更旧的记录
|
||||
filtered_items = []
|
||||
|
||||
# 需要将end_ids的key从QueryType转换为GachaType,给400赋值为301的值即可
|
||||
if "301" in end_ids:
|
||||
end_ids["400"] = end_ids["301"]
|
||||
|
||||
for item in gacha_log['data']:
|
||||
gacha_type = str(item.get('GachaType', ''))
|
||||
item_id = item.get('Id', 0)
|
||||
|
||||
Reference in New Issue
Block a user