mirror of
https://github.com/Remik1r3n/maimaiDX-Api.git
synced 2025-05-20 04:17:28 +08:00
初版可用AimeDB模拟器
This commit is contained in:
parent
a11d5b1246
commit
b4ca3d5d68
65
Standalone/DummyAimeDBServer.py
Normal file
65
Standalone/DummyAimeDBServer.py
Normal file
@ -0,0 +1,65 @@
|
||||
# 舞萌DX AimeDB 服务器模拟实现
|
||||
# 适用于舞萌DX 2024
|
||||
# 理论可用于 HDD 登号等(这种情况下自行修改 hosts
|
||||
|
||||
## 配置
|
||||
# 0 返回本地生成的假结果
|
||||
# 1 原样返回官方服务器的结果
|
||||
useOfficialServer = 0
|
||||
# 本地生成假结果时候,总是返回这个UID
|
||||
DUMMY_USER_ID = 10086
|
||||
|
||||
from fastapi import (
|
||||
FastAPI,
|
||||
Request
|
||||
)
|
||||
from fastapi.responses import (
|
||||
PlainTextResponse,
|
||||
JSONResponse
|
||||
)
|
||||
import 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)
|
Loading…
x
Reference in New Issue
Block a user