mirror of
https://github.com/wess09/AzurLaneAutoScript.git
synced 2026-05-14 05:38:10 +08:00
fix
This commit is contained in:
parent
e8658a3c4d
commit
2f7f43947f
2
.github/scripts/build_git_over_cdn.py
vendored
2
.github/scripts/build_git_over_cdn.py
vendored
@ -42,7 +42,7 @@ def build_pack(latest, old, output_dir):
|
|||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Build git-over-cdn update packs.")
|
parser = argparse.ArgumentParser(description="Build git-over-cdn update packs.")
|
||||||
parser.add_argument("--branch", default="master")
|
parser.add_argument("--branch", default="master")
|
||||||
parser.add_argument("--history", type=int, default=50)
|
parser.add_argument("--history", type=int, default=1)
|
||||||
parser.add_argument("--output", default="dist/git-over-cdn")
|
parser.add_argument("--output", default="dist/git-over-cdn")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|||||||
20
.github/scripts/upload_123pan.py
vendored
20
.github/scripts/upload_123pan.py
vendored
@ -6,6 +6,7 @@ import time
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from requests import RequestException
|
||||||
|
|
||||||
|
|
||||||
API_BASE = "https://open-api.123pan.com"
|
API_BASE = "https://open-api.123pan.com"
|
||||||
@ -16,6 +17,21 @@ class Pan123Error(RuntimeError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def request_with_retry(method, url, attempts=5, timeout=(30, 600), **kwargs):
|
||||||
|
last_error = None
|
||||||
|
for attempt in range(1, attempts + 1):
|
||||||
|
try:
|
||||||
|
return requests.request(method, url, timeout=timeout, **kwargs)
|
||||||
|
except RequestException as e:
|
||||||
|
last_error = e
|
||||||
|
if attempt == attempts:
|
||||||
|
break
|
||||||
|
wait = min(2 ** attempt, 30)
|
||||||
|
print(f"request failed, retrying in {wait}s ({attempt}/{attempts}): {e}")
|
||||||
|
time.sleep(wait)
|
||||||
|
raise last_error
|
||||||
|
|
||||||
|
|
||||||
def md5_file(path):
|
def md5_file(path):
|
||||||
digest = hashlib.md5()
|
digest = hashlib.md5()
|
||||||
with path.open("rb") as f:
|
with path.open("rb") as f:
|
||||||
@ -29,7 +45,7 @@ def api_json(method, url, token=None, **kwargs):
|
|||||||
headers["Platform"] = PLATFORM
|
headers["Platform"] = PLATFORM
|
||||||
if token:
|
if token:
|
||||||
headers["Authorization"] = f"Bearer {token}"
|
headers["Authorization"] = f"Bearer {token}"
|
||||||
response = requests.request(method, url, headers=headers, timeout=120, **kwargs)
|
response = request_with_retry(method, url, headers=headers, **kwargs)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if data.get("code") == 20103:
|
if data.get("code") == 20103:
|
||||||
@ -90,6 +106,7 @@ def upload_slices(token, create_data, path):
|
|||||||
data=data,
|
data=data,
|
||||||
files=files,
|
files=files,
|
||||||
)
|
)
|
||||||
|
print(f"uploaded slice {slice_no}: {path}")
|
||||||
slice_no += 1
|
slice_no += 1
|
||||||
|
|
||||||
|
|
||||||
@ -144,6 +161,7 @@ def main():
|
|||||||
path for path in source.rglob("*")
|
path for path in source.rglob("*")
|
||||||
if path.is_file() and (path.name == "latest.json" or path.suffix == ".zip")
|
if path.is_file() and (path.name == "latest.json" or path.suffix == ".zip")
|
||||||
)
|
)
|
||||||
|
print(f"uploading {len(files)} file(s) from {source} to /{args.remote_prefix.strip('/')}")
|
||||||
for path in files:
|
for path in files:
|
||||||
upload_file(token, args.parent_file_id, source, path, args.remote_prefix)
|
upload_file(token, args.parent_file_id, source, path, args.remote_prefix)
|
||||||
|
|
||||||
|
|||||||
13
.github/workflows/git-over-cdn-123pan.yml
vendored
13
.github/workflows/git-over-cdn-123pan.yml
vendored
@ -6,7 +6,7 @@ on:
|
|||||||
history:
|
history:
|
||||||
description: "How many old commits to build packs for"
|
description: "How many old commits to build packs for"
|
||||||
required: false
|
required: false
|
||||||
default: "50"
|
default: "1"
|
||||||
parent_file_id:
|
parent_file_id:
|
||||||
description: "123pan parent folder fileID, defaults to PAN123_PARENT_FILE_ID secret or azur folder"
|
description: "123pan parent folder fileID, defaults to PAN123_PARENT_FILE_ID secret or azur folder"
|
||||||
required: false
|
required: false
|
||||||
@ -32,11 +32,14 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: master
|
ref: master
|
||||||
|
|
||||||
|
- name: Install uv
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
|
|
||||||
- name: Build git-over-cdn packs
|
- name: Build git-over-cdn packs
|
||||||
run: |
|
run: |
|
||||||
python .github/scripts/build_git_over_cdn.py \
|
uv run python .github/scripts/build_git_over_cdn.py \
|
||||||
--branch master \
|
--branch master \
|
||||||
--history "${{ github.event.inputs.history || '50' }}" \
|
--history "${{ github.event.inputs.history || '1' }}" \
|
||||||
--output dist/git-over-cdn
|
--output dist/git-over-cdn
|
||||||
|
|
||||||
- name: Upload to 123pan
|
- name: Upload to 123pan
|
||||||
@ -47,10 +50,10 @@ jobs:
|
|||||||
PAN123_PARENT_FILE_ID_INPUT: ${{ github.event.inputs.parent_file_id }}
|
PAN123_PARENT_FILE_ID_INPUT: ${{ github.event.inputs.parent_file_id }}
|
||||||
PAN123_REMOTE_PREFIX_INPUT: ${{ github.event.inputs.remote_prefix }}
|
PAN123_REMOTE_PREFIX_INPUT: ${{ github.event.inputs.remote_prefix }}
|
||||||
run: |
|
run: |
|
||||||
python -m pip install requests
|
uv pip install --system requests
|
||||||
PAN123_PARENT_FILE_ID="${PAN123_PARENT_FILE_ID_INPUT:-${PAN123_PARENT_FILE_ID_SECRET:-31540282}}"
|
PAN123_PARENT_FILE_ID="${PAN123_PARENT_FILE_ID_INPUT:-${PAN123_PARENT_FILE_ID_SECRET:-31540282}}"
|
||||||
PAN123_REMOTE_PREFIX="${PAN123_REMOTE_PREFIX_INPUT:-AzurPilot_master}"
|
PAN123_REMOTE_PREFIX="${PAN123_REMOTE_PREFIX_INPUT:-AzurPilot_master}"
|
||||||
python .github/scripts/upload_123pan.py \
|
uv run python .github/scripts/upload_123pan.py \
|
||||||
--source dist/git-over-cdn \
|
--source dist/git-over-cdn \
|
||||||
--parent-file-id "$PAN123_PARENT_FILE_ID" \
|
--parent-file-id "$PAN123_PARENT_FILE_ID" \
|
||||||
--remote-prefix "$PAN123_REMOTE_PREFIX"
|
--remote-prefix "$PAN123_REMOTE_PREFIX"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user