From 4ff8a17f9afc5cfc4b1aa9fa47bed3ee995347c6 Mon Sep 17 00:00:00 2001 From: LeeCQ Date: Sat, 23 Mar 2024 23:30:57 +0800 Subject: [PATCH] =?UTF-8?q?Actions=20=E5=88=9B=E5=BB=BAstorage=E6=97=B6?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/alist-sync.yaml | 5 ---- tools/create_storage.py | 41 +++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.github/workflows/alist-sync.yaml b/.github/workflows/alist-sync.yaml index a296286..5aca062 100644 --- a/.github/workflows/alist-sync.yaml +++ b/.github/workflows/alist-sync.yaml @@ -51,20 +51,15 @@ jobs: ./alist/data - name: Install and Init Alist Server - env: - _ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }} run: | sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime bash -ex bootstrap.sh install # init-alist 总是会重置管理员密码为环境变量。 bash -x bootstrap.sh alist-init - - name: Create Storage for Alist if load cache failed if: github.event.inputs.reload_storage == 'true' || steps.alist-data-cache.outputs.cache-hit != 'true' env: - _ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }} - _ALIST_BACKUP: ${{secrets.ALIST_BACKUP}} _ALIST_BACKUP_URL: ${{secrets.ALIST_BACKUP_URL}} _ALIST_BACKUP_USERNAME: ${{secrets.ALIST_BACKUP_USERNAME}} diff --git a/tools/create_storage.py b/tools/create_storage.py index 1dedfef..4fcedd6 100644 --- a/tools/create_storage.py +++ b/tools/create_storage.py @@ -8,8 +8,11 @@ import datetime import json import os +import time from pathlib import Path +import httpx + from alist_sdk import Storage from alist_sdk.tools.client import ExtraClient @@ -18,7 +21,7 @@ alist_config = json.loads(PROJECT_ROOT.joinpath("alist/data/config.json").read_text()) alist_port = alist_config["scheme"]["http_port"] -admin_password = os.getenv("_ALIST_ADMIN_PASSWORD", ) or "123456" +admin_password = os.getenv("_ALIST_ADMIN_PASSWORD", "123456") remote_url = os.getenv("_ALIST_BACKUP_URL") remote_username = os.getenv("_ALIST_BACKUP_USERNAME") @@ -70,18 +73,30 @@ } ) ) -print(res) +print("创建本地存储状态", res) -if remote_url: - local_client.import_config_from_other_client( - base_url=remote_url, - username=remote_username, - password=remote_password, - verify=False, - ) - exit(0) +def create_storage(retry=3): + try: + if remote_url: + local_client.import_config_from_other_client( + base_url=remote_url, + username=remote_username, + password=remote_password, + verify=False, + ) + exit(0) + + _bk_file = PROJECT_ROOT.joinpath("alist-backup-config.json") + if _bk_file.exists(): + local_client.import_configs(json.loads(_bk_file.read_text())) + except httpx.ReadTimeout as _e: + if retry <= 0: + raise _e + + print(f"超时 {retry = }") + time.sleep(3) + create_storage(retry=retry - 1) + -_bk_file = PROJECT_ROOT.joinpath("alist-backup-config.json") -if _bk_file.exists(): - local_client.import_configs(json.loads(_bk_file.read_text())) +create_storage()