🚚 Change resources repo

This commit is contained in:
omg-xtao 2022-11-03 18:33:13 +08:00 committed by GitHub
parent 7ce85937f1
commit 56af09c703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -28,6 +28,7 @@ from core.error import ServiceNotFoundError
# noinspection PyProtectedMember # noinspection PyProtectedMember
from core.plugin import Plugin, _Plugin from core.plugin import Plugin, _Plugin
from core.service import Service from core.service import Service
from metadata.scripts.metadatas import make_github_fast
from utils.const import PLUGIN_DIR, PROJECT_ROOT from utils.const import PLUGIN_DIR, PROJECT_ROOT
from utils.log import logger from utils.log import logger
@ -214,7 +215,7 @@ class Bot:
setattr( setattr(
genshin.utility.extdb, genshin.utility.extdb,
i, i,
getattr(genshin.utility.extdb, i).replace("githubusercontent.com", "fastgit.org"), make_github_fast(getattr(genshin.utility.extdb, i)),
) )
await genshin.utility.update_characters_enka() await genshin.utility.update_characters_enka()
except Exception as exc: # pylint: disable=W0703 except Exception as exc: # pylint: disable=W0703

View File

@ -8,7 +8,11 @@ from httpx import AsyncClient, RemoteProtocolError, Response, URL
from utils.const import AMBR_HOST, PROJECT_ROOT from utils.const import AMBR_HOST, PROJECT_ROOT
from utils.log import logger from utils.log import logger
__all__ = ["update_metadata_from_ambr", "update_metadata_from_github"] __all__ = ["update_metadata_from_ambr", "update_metadata_from_github", "make_github_fast"]
RESOURCE_REPO = "tamilpp25/Grasscutter_Resources"
RESOURCE_BRANCH = "3.2"
RESOURCE_ROOT = "Resources"
RESOURCE_DEFAULT_PATH = f"{RESOURCE_REPO}/{RESOURCE_BRANCH}/{RESOURCE_ROOT}/"
client = AsyncClient() client = AsyncClient()
@ -44,10 +48,10 @@ async def update_metadata_from_github(overwrite: bool = True):
return return
hosts = [ hosts = [
URL("https://ghproxy.net/https://raw.githubusercontent.com/Dimbreath/GenshinData/master/"), URL(f"https://ghproxy.net/https://raw.githubusercontent.com/{RESOURCE_DEFAULT_PATH}"),
URL("https://github.91chi.fun/https://raw.githubusercontent.com/Dimbreath/GenshinData/master/"), URL(f"https://github.91chi.fun/https://raw.githubusercontent.com/{RESOURCE_DEFAULT_PATH}"),
URL("https://raw.fastgit.org/Dimbreath/GenshinData/master/"), URL(f"https://raw.fastgit.org/{RESOURCE_DEFAULT_PATH}"),
URL("https://raw.githubusercontent.com/Dimbreath/GenshinData/master/"), URL(f"https://raw.githubusercontent.com/{RESOURCE_DEFAULT_PATH}"),
] ]
for num, host in enumerate(hosts): for num, host in enumerate(hosts):
try: try:
@ -84,7 +88,7 @@ async def update_metadata_from_github(overwrite: bool = True):
async with client.stream("GET", text_map_url) as response: async with client.stream("GET", text_map_url) as response:
async for line in response.aiter_lines(): async for line in response.aiter_lines():
if (string_id := (splits := line.split(":"))[0].strip(' "')) in string_ids: if (string_id := (splits := line.split(":"))[0].strip(' "')) in string_ids:
text_map_json_data.update({string_id: splits[1].strip('\n ,"')}) text_map_json_data[string_id] = splits[1].strip('\n ,"')
string_ids.remove(string_id) string_ids.remove(string_id)
if not string_ids: if not string_ids:
break break
@ -122,3 +126,9 @@ async def update_metadata_from_github(overwrite: bool = True):
logger.error(f"在从 {host} 下载元数据的过程中遇到了错误: {repr(e)}") logger.error(f"在从 {host} 下载元数据的过程中遇到了错误: {repr(e)}")
continue continue
raise e raise e
def make_github_fast(url: str) -> str:
url = url.replace("raw.githubusercontent.com", "raw.fastgit.org")
url = url.replace("Dimbreath/GenshinData/master/", RESOURCE_DEFAULT_PATH)
return url