Initial commit: Add maimaiDX API web application with AimeDB scanning and logging features

This commit is contained in:
kejiz
2025-09-18 10:19:08 +08:00
commit 4e83f159f0
84 changed files with 14012 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
# 舞萌DX AimeDB 服务器模拟实现
# 适用于舞萌DX 2024
# 理论可用于 HDD 登号等(这种情况下自行修改 hosts
# SGWCMAID111111111111AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
## 配置
# 0 返回本地生成的假结果
# 1 原样返回官方服务器的结果
useOfficialServer = 0
from loguru import logger
# 解析命令行参数,作为用户 ID
import argparse
try:
parser = argparse.ArgumentParser(description="舞萌DX AimeDB 服务器模拟实现")
#parser.add_argument("userId", type=int, help="用户 ID")
#args = parser.parse_args()
#DUMMY_USER_ID = args.userId
raise Exception("未传入用户 ID")
except Exception as e:
logger.warning(f"{e},未传入用户 ID使用默认值")
DUMMY_USER_ID = 1
from fastapi import (
FastAPI,
Request
)
from fastapi.responses import (
PlainTextResponse,
JSONResponse
)
import rapidjson as json
import uvicorn
from loguru import logger
# 将当前目录的父目录加入到 sys.path 中
import sys
from pathlib import Path
current_dir = Path(__file__).resolve().parent
parent_dir = current_dir.parent
sys.path.append(str(parent_dir))
from API_AimeDB import implAimeDB, calcSEGAAimeDBAuthKey
app = FastAPI()
@app.post('/qrcode/api/alive_check')
async def qrcode_alive_check_api():
return PlainTextResponse('alive')
@app.post('/wc_aime/api/alive_check')
async def wc_aime_alive_check_api():
return PlainTextResponse('alive')
@app.post('/wc_aime/api/get_data')
async def get_data_dummy_api(request: Request):
gotRequest = json.loads((await request.body()).decode())
if useOfficialServer == 0:
fakeTimestamp = str(int(gotRequest['timestamp'])+3)
currentResponse = {
'errorID': 0,
'key': calcSEGAAimeDBAuthKey(str(DUMMY_USER_ID), fakeTimestamp),
'timestamp': fakeTimestamp,
'userID': DUMMY_USER_ID
}
logger.info(f"返回假结果: {currentResponse}")
return JSONResponse(currentResponse)
elif useOfficialServer == 1:
# 发给真正的 AimeDB
realAimeDBResponse = implAimeDB(gotRequest['qrCode'], True)
return JSONResponse(json.loads(realAimeDBResponse))
else:
pass
if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=80)