mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🐛 文件下载逻辑修改
This commit is contained in:
parent
682d19aa2b
commit
ce97dedc5f
@ -36,9 +36,10 @@ def init_mocked_api(mocked_api: MockRouter) -> None:
|
|||||||
).respond(json=get_response_json("zhenxun_github_sub_tree.json"))
|
).respond(json=get_response_json("zhenxun_github_sub_tree.json"))
|
||||||
|
|
||||||
mocked_api.head(
|
mocked_api.head(
|
||||||
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins/main/plugins.json",
|
"https://raw.githubusercontent.com/",
|
||||||
name="head_basic_plugins",
|
name="head_raw",
|
||||||
).respond(200, text="")
|
).respond(200, text="")
|
||||||
|
|
||||||
mocked_api.get(
|
mocked_api.get(
|
||||||
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins/main/plugins.json",
|
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins/main/plugins.json",
|
||||||
name="basic_plugins",
|
name="basic_plugins",
|
||||||
@ -47,6 +48,7 @@ def init_mocked_api(mocked_api: MockRouter) -> None:
|
|||||||
"https://cdn.jsdelivr.net/gh/zhenxun-org/zhenxun_bot_plugins@main/plugins.json",
|
"https://cdn.jsdelivr.net/gh/zhenxun-org/zhenxun_bot_plugins@main/plugins.json",
|
||||||
name="basic_plugins_jsdelivr",
|
name="basic_plugins_jsdelivr",
|
||||||
).respond(200, json=get_response_json("basic_plugins.json"))
|
).respond(200, json=get_response_json("basic_plugins.json"))
|
||||||
|
|
||||||
mocked_api.get(
|
mocked_api.get(
|
||||||
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins_index/index/plugins.json",
|
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins_index/index/plugins.json",
|
||||||
name="extra_plugins",
|
name="extra_plugins",
|
||||||
@ -55,6 +57,7 @@ def init_mocked_api(mocked_api: MockRouter) -> None:
|
|||||||
"https://cdn.jsdelivr.net/gh/zhenxun-org/zhenxun_bot_plugins_index@index/plugins.json",
|
"https://cdn.jsdelivr.net/gh/zhenxun-org/zhenxun_bot_plugins_index@index/plugins.json",
|
||||||
name="extra_plugins_jsdelivr",
|
name="extra_plugins_jsdelivr",
|
||||||
).respond(200, json=get_response_json("extra_plugins.json"))
|
).respond(200, json=get_response_json("extra_plugins.json"))
|
||||||
|
|
||||||
mocked_api.get(
|
mocked_api.get(
|
||||||
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins/main/plugins/search_image/__init__.py",
|
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins/main/plugins/search_image/__init__.py",
|
||||||
name="search_image_plugin_file_init",
|
name="search_image_plugin_file_init",
|
||||||
|
|||||||
@ -70,11 +70,7 @@ class RepoInfo(BaseModel):
|
|||||||
"""获取最快下载地址格式"""
|
"""获取最快下载地址格式"""
|
||||||
raw_format = "https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path}"
|
raw_format = "https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path}"
|
||||||
patterns: dict[str, str] = {
|
patterns: dict[str, str] = {
|
||||||
(
|
"https://raw.githubusercontent.com/": raw_format,
|
||||||
"https://raw.githubusercontent.com"
|
|
||||||
"/zhenxun-org/zhenxun_bot_plugins/main"
|
|
||||||
"/plugins.json"
|
|
||||||
): raw_format,
|
|
||||||
"https://ghproxy.cc/": f"https://ghproxy.cc/{raw_format}",
|
"https://ghproxy.cc/": f"https://ghproxy.cc/{raw_format}",
|
||||||
"https://mirror.ghproxy.com/": f"https://mirror.ghproxy.com/{raw_format}",
|
"https://mirror.ghproxy.com/": f"https://mirror.ghproxy.com/{raw_format}",
|
||||||
"https://gh-proxy.com/": f"https://gh-proxy.com/{raw_format}",
|
"https://gh-proxy.com/": f"https://gh-proxy.com/{raw_format}",
|
||||||
|
|||||||
@ -196,18 +196,19 @@ class AsyncHttpx:
|
|||||||
for _ in range(3):
|
for _ in range(3):
|
||||||
if not stream:
|
if not stream:
|
||||||
try:
|
try:
|
||||||
content = (
|
response = await cls.get(
|
||||||
await cls.get(
|
url,
|
||||||
url,
|
params=params,
|
||||||
params=params,
|
headers=headers,
|
||||||
headers=headers,
|
cookies=cookies,
|
||||||
cookies=cookies,
|
use_proxy=use_proxy,
|
||||||
use_proxy=use_proxy,
|
proxy=proxy,
|
||||||
proxy=proxy,
|
timeout=timeout,
|
||||||
timeout=timeout,
|
follow_redirects=True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
).content
|
response.raise_for_status()
|
||||||
|
content = response.content
|
||||||
async with aiofiles.open(path, "wb") as wf:
|
async with aiofiles.open(path, "wb") as wf:
|
||||||
await wf.write(content)
|
await wf.write(content)
|
||||||
logger.info(f"下载 {url} 成功.. Path:{path.absolute()}")
|
logger.info(f"下载 {url} 成功.. Path:{path.absolute()}")
|
||||||
@ -230,8 +231,10 @@ class AsyncHttpx:
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
follow_redirects=True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) as response:
|
) as response:
|
||||||
|
response.raise_for_status()
|
||||||
logger.info(
|
logger.info(
|
||||||
f"开始下载 {path.name}.. Path: {path.absolute()}"
|
f"开始下载 {path.name}.. Path: {path.absolute()}"
|
||||||
)
|
)
|
||||||
@ -347,10 +350,9 @@ class AsyncHttpx:
|
|||||||
begin_time = time.time()
|
begin_time = time.time()
|
||||||
|
|
||||||
response = await client.head(url=url, timeout=6)
|
response = await client.head(url=url, timeout=6)
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
elapsed_time = (time.time() - begin_time) * 1000
|
elapsed_time = (time.time() - begin_time) * 1000
|
||||||
content_length = int(response.headers["content-length"])
|
content_length = int(response.headers.get("content-length", 0))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"url": url,
|
"url": url,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user