Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmozhijin committed Sep 16, 2024
1 parent a6f6dac commit a39705a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 7 additions & 8 deletions build_helper/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import requests
from pySmartDL import SmartDL

import urllib.error
from .logger import logger

HEADER = {
Expand Down Expand Up @@ -46,24 +46,23 @@ def dl2(url: str, path: str, retry: int = 6, headers: dict | None = None) -> Sma
def wait_dl_tasks(dl_tasks: list[SmartDL]) -> None:
for task in dl_tasks:
task.wait()
while not task.isSuccessful() or task.attemps_limit < task.current_attemp:
logger.warning("下载: %s 失败,重试第%s/%s次...", task.url, task.current_attemp, task.attemps_limit)
task.retry()
task.wait()
if task.isSuccessful():
logger.info("下载: %s 成功", task.url)
else:
logger.error("下载: %s 失败", task.url)
raise task.errors[-1]
dl_tasks.clear()

def get_gh_repo_last_releases(repo: str, token: str | None = None) -> dict | None:
return gh_api_request(f"https://api.github.com/repos/{repo}/releases/latest", token)

def gh_api_request(url: str, token: str | None = None) -> dict | None:
headers = {"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28"}
headers = {
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
}
if token:
headers["Authorization"] = f'Bearer {token}'
headers["Authorization"] = f'token {token}'
response = request_get(url, headers=headers)
if isinstance(response, str):
obj = json.loads(response)
Expand Down
7 changes: 6 additions & 1 deletion build_helper/utils/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def dl_artifact(name: str, path: str) -> str:
if not token:
msg = "没有可用的token"
raise KeyError(msg)
dl = dl2(dl_url, path, headers={"Authorization": f"Bearer {token}"})
headers = {
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": f'token {token}',
}
dl = dl2(dl_url, path, headers=headers)
wait_dl_tasks([dl])
return dl.get_dest()

Expand Down

0 comments on commit a39705a

Please sign in to comment.