🐛 Fix AssetsService to adapt to ambr

This commit is contained in:
Karako 2024-03-19 17:45:35 +08:00
parent 042e4e91ca
commit df6b0e31ba
No known key found for this signature in database
2 changed files with 8 additions and 25 deletions

View File

@ -1,9 +1,5 @@
"""用于下载和管理角色、武器、材料等的图标"""
from __future__ import annotations
import asyncio
import re
from abc import ABC, abstractmethod
from functools import cached_property, lru_cache, partial
from multiprocessing import RLock as Lock
@ -27,6 +23,11 @@ from utils.const import AMBR_HOST, ENKA_HOST, PROJECT_ROOT
from utils.log import logger
from utils.typedefs import StrOrInt, StrOrURL
try:
import regex as re
except ImportError:
import re
if TYPE_CHECKING:
from httpx import Response
from multiprocessing.synchronize import RLock
@ -250,6 +251,8 @@ class _AvatarAssets(_AssetsService):
temp = target
result = _AvatarAssets(self.client)
if isinstance(target, str):
if targets := re.findall(r"^(1000000\d)-.*$", target):
target = targets[0]
try:
target = int(target)
except ValueError:
@ -467,7 +470,7 @@ class AssetsService(BaseService.Dependence):
async def initialize(self) -> None: # pylint: disable=R0201
"""启动 AssetsService 服务,刷新元数据"""
logger.info("正在刷新元数据")
# todo 这3个任务同时异步下载
# TODO:同时异步下载
await update_metadata_from_github(False)
await update_metadata_from_ambr(False)
logger.info("刷新元数据成功")

View File

@ -39,10 +39,6 @@ class _AssetsService(ABC):
def game_name(self) -> str:
"""游戏数据中的名称"""
@property
def honey_id(self) -> str:
"""当前资源在 Honey Impact 所对应的 ID"""
@property
def path(self) -> Path:
"""当前资源的文件夹"""
@ -66,11 +62,6 @@ class _AssetsService(ABC):
def game_name_map(self) -> dict[str, str]:
"""游戏中的图标名"""
@abstractmethod
@property
def honey_name_map(self) -> dict[str, str]:
"""来自honey的图标名"""
class _AvatarAssets(_AssetsService):
enka: EnkaCharacterAsset | None
@ -86,8 +77,6 @@ class _AvatarAssets(_AssetsService):
gacha_card: ICON_TYPE
"""抽卡卡片"""
@property
def honey_name_map(self) -> dict[str, str]: ...
@property
def game_name_map(self) -> dict[str, str]: ...
@property
@ -104,16 +93,12 @@ class _WeaponAssets(_AssetsService):
gacha: ICON_TYPE
"""抽卡立绘"""
@property
def honey_name_map(self) -> dict[str, str]: ...
@property
def game_name_map(self) -> dict[str, str]: ...
def __call__(self, target: StrOrInt) -> Self: ...
def game_name(self) -> str: ...
class _MaterialAssets(_AssetsService):
@property
def honey_name_map(self) -> dict[str, str]: ...
@property
def game_name_map(self) -> dict[str, str]: ...
def __call__(self, target: StrOrInt) -> Self: ...
@ -135,8 +120,6 @@ class _ArtifactAssets(_AssetsService):
circlet: ICON_TYPE
"""理之冠"""
@property
def honey_name_map(self) -> dict[str, str]: ...
@property
def game_name_map(self) -> dict[str, str]: ...
def game_name(self) -> str: ...
@ -149,9 +132,6 @@ class _NamecardAssets(_AssetsService):
profile: ICON_TYPE
"""个人资料名片背景"""
@property
def honey_name_map(self) -> dict[str, str]: ...
@property
def game_name_map(self) -> dict[str, str]: ...
def game_name(self) -> str: ...