Merge branch 'feature/refactor-backend' of github.com:DLmaster361/AUTO_MAA into feature/refactor-backend
This commit is contained in:
@@ -64,3 +64,21 @@ async def get_apps_info() -> InfoOut:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return InfoOut(code=500, status="error", message=str(e), data={})
|
return InfoOut(code=500, status="error", message=str(e), data={})
|
||||||
return InfoOut(data=data)
|
return InfoOut(data=data)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post(
|
||||||
|
"/get/overview", summary="信息总览", response_model=InfoOut, status_code=200
|
||||||
|
)
|
||||||
|
async def add_overview() -> InfoOut:
|
||||||
|
try:
|
||||||
|
if_get_maa_stage, data = await Config.get_official_activity_stages()
|
||||||
|
|
||||||
|
return InfoOut(
|
||||||
|
status="success" if if_get_maa_stage else "warning",
|
||||||
|
message="获取活动关卡信息成功" if if_get_maa_stage else "未能获取活动关卡信息",
|
||||||
|
data=data,
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return InfoOut(code=500, status="error", message=str(e), data={})
|
||||||
|
|
||||||
|
|||||||
@@ -20,21 +20,19 @@
|
|||||||
# Contact: DLmaster_361@163.com
|
# Contact: DLmaster_361@163.com
|
||||||
|
|
||||||
|
|
||||||
|
import calendar
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
from collections import defaultdict
|
||||||
|
from datetime import datetime, timedelta, date, timezone
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Literal, Optional, Tuple
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import truststore
|
import truststore
|
||||||
import calendar
|
|
||||||
from datetime import datetime, timedelta, date
|
|
||||||
from pathlib import Path
|
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
|
|
||||||
from typing import Dict, List, Literal, Optional, Any
|
|
||||||
|
|
||||||
from app.utils import get_logger
|
|
||||||
from app.models.ConfigBase import *
|
from app.models.ConfigBase import *
|
||||||
|
from app.utils import get_logger
|
||||||
|
|
||||||
logger = get_logger("配置管理")
|
logger = get_logger("配置管理")
|
||||||
|
|
||||||
@@ -548,7 +546,6 @@ class GeneralConfig(ConfigBase):
|
|||||||
|
|
||||||
|
|
||||||
class AppConfig(GlobalConfig):
|
class AppConfig(GlobalConfig):
|
||||||
|
|
||||||
VERSION = "5.0.0.1"
|
VERSION = "5.0.0.1"
|
||||||
|
|
||||||
CLASS_BOOK = {
|
CLASS_BOOK = {
|
||||||
@@ -1053,6 +1050,128 @@ class AppConfig(GlobalConfig):
|
|||||||
|
|
||||||
return if_get_maa_stage, stage_dict
|
return if_get_maa_stage, stage_dict
|
||||||
|
|
||||||
|
async def get_official_activity_stages(
|
||||||
|
self,
|
||||||
|
url: str = "https://api.maa.plus/MaaAssistantArknights/api/gui/StageActivity.json",
|
||||||
|
timeout: int = 10,
|
||||||
|
) -> Tuple[bool, Dict[str, List[Dict[str, str]]]]:
|
||||||
|
"""
|
||||||
|
获取 Official 区服当前开放的活动关卡(仅返回 Display/Value/Drop)。
|
||||||
|
返回:
|
||||||
|
(if_success, {"ALL": [ {"Display": "...", "Value": "...", "Drop": "..."}, ... ]})
|
||||||
|
"""
|
||||||
|
materials_map: Dict[str, str] = {
|
||||||
|
"30165": "重相位对映体",
|
||||||
|
"30155": "烧结核凝晶",
|
||||||
|
"30145": "晶体电子单元",
|
||||||
|
"30135": "D32钢",
|
||||||
|
"30125": "双极纳米片",
|
||||||
|
"30115": "聚合剂",
|
||||||
|
"31094": "手性屈光体",
|
||||||
|
"31093": "类凝结核",
|
||||||
|
"31084": "环烃预制体",
|
||||||
|
"31083": "环烃聚质",
|
||||||
|
"31074": "固化纤维板",
|
||||||
|
"31073": "褐素纤维",
|
||||||
|
"31064": "转质盐聚块",
|
||||||
|
"31063": "转质盐组",
|
||||||
|
"31054": "切削原液",
|
||||||
|
"31053": "化合切削液",
|
||||||
|
"31044": "精炼溶剂",
|
||||||
|
"31043": "半自然溶剂",
|
||||||
|
"31034": "晶体电路",
|
||||||
|
"31033": "晶体元件",
|
||||||
|
"31024": "炽合金块",
|
||||||
|
"31023": "炽合金",
|
||||||
|
"31014": "聚合凝胶",
|
||||||
|
"31013": "凝胶",
|
||||||
|
"30074": "白马醇",
|
||||||
|
"30073": "扭转醇",
|
||||||
|
"30084": "三水锰矿",
|
||||||
|
"30083": "轻锰矿",
|
||||||
|
"30094": "五水研磨石",
|
||||||
|
"30093": "研磨石",
|
||||||
|
"30104": "RMA70-24",
|
||||||
|
"30103": "RMA70-12",
|
||||||
|
"30014": "提纯源岩",
|
||||||
|
"30013": "固源岩组",
|
||||||
|
"30012": "固源岩",
|
||||||
|
"30011": "源岩",
|
||||||
|
"30064": "改量装置",
|
||||||
|
"30063": "全新装置",
|
||||||
|
"30062": "装置",
|
||||||
|
"30061": "破损装置",
|
||||||
|
"30034": "聚酸酯块",
|
||||||
|
"30033": "聚酸酯组",
|
||||||
|
"30032": "聚酸酯",
|
||||||
|
"30031": "酯原料",
|
||||||
|
"30024": "糖聚块",
|
||||||
|
"30023": "糖组",
|
||||||
|
"30022": "糖",
|
||||||
|
"30021": "代糖",
|
||||||
|
"30044": "异铁块",
|
||||||
|
"30043": "异铁组",
|
||||||
|
"30042": "异铁",
|
||||||
|
"30041": "异铁碎片",
|
||||||
|
"30054": "酮阵列",
|
||||||
|
"30053": "酮凝集组",
|
||||||
|
"30052": "酮凝集",
|
||||||
|
"30051": "双酮"
|
||||||
|
}
|
||||||
|
|
||||||
|
def normalize_drop(value: str) -> str:
|
||||||
|
# 去前后空格与常见零宽字符
|
||||||
|
s = str(value).strip()
|
||||||
|
s = re.sub(r"[\u200b\u200c\u200d\ufeff]", "", s)
|
||||||
|
return s
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = requests.get(url, timeout=timeout, proxies=self.get_proxies())
|
||||||
|
except Exception:
|
||||||
|
return False, {"ALL": []}
|
||||||
|
|
||||||
|
if resp.status_code != 200:
|
||||||
|
return False, {"ALL": []}
|
||||||
|
|
||||||
|
try:
|
||||||
|
payload = resp.json()
|
||||||
|
except Exception:
|
||||||
|
return False, {"ALL": []}
|
||||||
|
|
||||||
|
now_utc = datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
def parse_utc(dt_str: str) -> datetime:
|
||||||
|
return datetime.strptime(dt_str, "%Y/%m/%d %H:%M:%S").replace(tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
results: List[Dict[str, Any]] = []
|
||||||
|
|
||||||
|
for s in payload.get("Official", {}).get("sideStoryStage", []):
|
||||||
|
act = s.get("Activity", {}) or {}
|
||||||
|
try:
|
||||||
|
start_utc = parse_utc(act["UtcStartTime"])
|
||||||
|
expire_utc = parse_utc(act["UtcExpireTime"])
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if start_utc <= now_utc < expire_utc:
|
||||||
|
raw_drop = s.get("Drop", "")
|
||||||
|
drop_id = normalize_drop(raw_drop)
|
||||||
|
|
||||||
|
if drop_id.isdigit():
|
||||||
|
drop_name = materials_map.get(drop_id, "未知材料")
|
||||||
|
else:
|
||||||
|
drop_name = "DESC:"+drop_id # 非纯数字,直接用文本.加一个DESC前缀方便前端区分
|
||||||
|
|
||||||
|
results.append({
|
||||||
|
"Display": s.get("Display", ""),
|
||||||
|
"Value": s.get("Value", ""),
|
||||||
|
"Drop": raw_drop,
|
||||||
|
"DropName": drop_name,
|
||||||
|
"Activity": s.get("Activity", {})
|
||||||
|
})
|
||||||
|
|
||||||
|
return True, {"ALL": results}
|
||||||
|
|
||||||
async def get_server_info(self, type: str) -> Dict[str, Any]:
|
async def get_server_info(self, type: str) -> Dict[str, Any]:
|
||||||
"""获取公告信息"""
|
"""获取公告信息"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user