feat: 对港澳台或境外用户更加友好

This commit is contained in:
ikun0014
2024-10-13 17:30:06 +08:00
parent 9a3668a2f4
commit 7f087983d3
4 changed files with 39 additions and 9 deletions

22
common/checkcn.py Normal file
View File

@@ -0,0 +1,22 @@
import os
import requests
from .log import log
from .stack_error import stack_error
def checkcn():
try:
req = requests.get('https://mips.kugou.com/check/iscn?&format=json')
body = req.json()
scn = bool(body['flag'])
if (not scn):
log.info(f"您在非中国大陆地区({body['country']})上使用了项目, 已自动切换回Github官方下载CDN")
os.environ['IS_CN'] = 'no'
return False
else:
os.environ['IS_CN'] = 'yes'
return True
except Exception as e:
os.environ['IS_CN'] = 'yes'
log.warning('❗ 检查服务器位置失败,已忽略,自动认为你在中国大陆')
log.warning(stack_error(e))
return False

View File

@@ -1,6 +1,7 @@
import os
from aiohttp import ClientSession, ConnectionTimeoutError
from common.checkcn import checkcn
from common.config import config
from common.dkey_merge import depotkey_merge
from common.migration import migrate
@@ -47,6 +48,8 @@ async def main(app_id: str, repos: list) -> bool:
log.error(f'⚠ App ID无效')
return False
app_id = app_id_list[0]
checkcn()
async with ClientSession() as session:
github_token = config.get("Github_Personal_Token", "")

View File

@@ -1,18 +1,22 @@
import os
from aiohttp import ClientError, ConnectionTimeoutError
from tqdm.asyncio import tqdm_asyncio
from .log import log
async def get(sha: str, path: str, repo: str, session, chunk_size: int = 1024) -> bytearray:
url_list = [
f'https://jsdelivr.pai233.top/gh/{repo}@{sha}/{path}',
f'https://cdn.jsdmirror.com/gh/{repo}@{sha}/{path}',
f'https://raw.gitmirror.com/{repo}/{sha}/{path}',
f'https://raw.dgithub.xyz/{repo}/{sha}/{path}',
f'https://gh.akass.cn/{repo}/{sha}/{path}',
f'https://raw.githubusercontent.com/{repo}/{sha}/{path}'
]
if os.environ.get('IS_CN') == 'yes':
url_list = [
f'https://jsdelivr.pai233.top/gh/{repo}@{sha}/{path}',
f'https://cdn.jsdmirror.com/gh/{repo}@{sha}/{path}',
f'https://raw.gitmirror.com/{repo}/{sha}/{path}',
f'https://raw.dgithub.xyz/{repo}/{sha}/{path}',
f'https://gh.akass.cn/{repo}/{sha}/{path}'
]
else:
url_list = [
f'https://raw.githubusercontent.com/{repo}/{sha}/{path}'
]
retry = 3
while retry > 0:
for url in url_list:

View File

@@ -2,6 +2,7 @@ aiofiles==24.1.0
aiohttp==3.10.2
colorama==0.4.6
colorlog==6.8.2
Requests==2.32.3
tqdm==4.66.5
ujson==5.10.0
vdf==3.4