From 2232e51509ec70d10a80b86c0f7bc48d6e079c3a Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 3 Jun 2024 07:09:30 +0800 Subject: [PATCH] add GITHUB_PROXY --- README.md | 1 + app/core/config.py | 2 ++ app/helper/plugin.py | 5 +++-- app/helper/resource.py | 5 +++-- update | 8 ++++---- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a82e90aa..2d9b2f0a 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ MoviePilot需要配套下载器和媒体服务器配合使用。 - **DOH_ENABLE:** DNS over HTTPS开关,`true`/`false`,默认`true`,开启后会使用DOH对api.themoviedb.org等域名进行解析,以减少被DNS污染的情况,提升网络连通性 - **META_CACHE_EXPIRE:** 元数据识别缓存过期时间(小时),数字型,不配置或者配置为0时使用系统默认(大内存模式为7天,否则为3天),调大该值可减少themoviedb的访问次数 - **GITHUB_TOKEN:** Github token,提高自动更新、插件安装等请求Github Api的限流阈值,格式:ghp_**** +- **GITHUB_PROXY:** Github代理地址,用于加速版本及插件升级安装,格式:`https://mirror.ghproxy.com/` - **DEV:** 开发者模式,`true`/`false`,默认`false`,仅用于本地开发使用,开启后会暂停所有定时任务,且插件代码文件的修改无需重启会自动重载生效 - **AUTO_UPDATE_RESOURCE**:启动时自动检测和更新资源包(站点索引及认证等),`true`/`false`,默认`true`,需要能正常连接Github,仅支持Docker镜像 --- diff --git a/app/core/config.py b/app/core/config.py index 1702ed19..75a989a0 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -220,6 +220,8 @@ class Settings(BaseSettings): PLUGIN_MARKET: str = "https://github.com/jxxghp/MoviePilot-Plugins,https://github.com/thsrite/MoviePilot-Plugins,https://github.com/honue/MoviePilot-Plugins,https://github.com/InfinityPacer/MoviePilot-Plugins" # Github token,提高请求api限流阈值 ghp_**** GITHUB_TOKEN: Optional[str] = None + # Github代理服务器,格式:https://mirror.ghproxy.com/ + GITHUB_PROXY: Optional[str] = '' # 自动检查和更新站点资源包(站点索引、认证等) AUTO_UPDATE_RESOURCE: bool = True # 元数据识别缓存过期时间(小时) diff --git a/app/helper/plugin.py b/app/helper/plugin.py index 544bf7f6..abf10c9d 100644 --- a/app/helper/plugin.py +++ b/app/helper/plugin.py @@ -20,7 +20,7 @@ class PluginHelper(metaclass=Singleton): 插件市场管理,下载安装插件到本地 """ - _base_url = "https://raw.githubusercontent.com/%s/%s/main/" + _base_url = f"{settings.GITHUB_PROXY}https://raw.githubusercontent.com/%s/%s/main/" _install_reg = f"{settings.MP_SERVER_HOST}/plugin/install/%s" @@ -157,9 +157,10 @@ class PluginHelper(metaclass=Singleton): return False, "文件列表为空" for item in _l: if item.get("download_url"): + download_url = f"{settings.GITHUB_PROXY}{item.get('download_url')}" # 下载插件文件 res = RequestUtils(proxies=settings.PROXY, - headers=settings.GITHUB_HEADERS, timeout=60).get_res(item["download_url"]) + headers=settings.GITHUB_HEADERS, timeout=60).get_res(download_url) if not res: return False, f"文件 {item.get('name')} 下载失败!" elif res.status_code != 200: diff --git a/app/helper/resource.py b/app/helper/resource.py index f08e27d6..8316807b 100644 --- a/app/helper/resource.py +++ b/app/helper/resource.py @@ -15,7 +15,7 @@ class ResourceHelper(metaclass=Singleton): 检测和更新资源包 """ # 资源包的git仓库地址 - _repo = "https://raw.githubusercontent.com/jxxghp/MoviePilot-Resources/main/package.json" + _repo = f"{settings.GITHUB_PROXY}https://raw.githubusercontent.com/jxxghp/MoviePilot-Resources/main/package.json" _files_api = f"https://api.github.com/repos/jxxghp/MoviePilot-Resources/contents/resources" _base_dir: Path = settings.ROOT_PATH @@ -87,9 +87,10 @@ class ResourceHelper(metaclass=Singleton): continue if item.get("download_url"): logger.info(f"开始更新资源文件:{item.get('name')} ...") + download_url = f"{settings.GITHUB_PROXY}{item.get('download_url')}" # 下载资源文件 res = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS, - timeout=180).get_res(item["download_url"]) + timeout=180).get_res(download_url) if not res: logger.error(f"文件 {item.get('name')} 下载失败!") elif res.status_code != 200: diff --git a/update b/update index 06be4e9f..a400cf2d 100644 --- a/update +++ b/update @@ -21,14 +21,14 @@ download_and_unzip() { install_backend_and_download_resources() { # 清理临时目录,上次安装失败可能有残留 rm -rf /tmp/* - if download_and_unzip "https://github.com/jxxghp/MoviePilot/archive/refs/${1}" "App"; then + if download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot/archive/refs/${1}" "App"; then echo "后端程序下载成功" pip install ${PIP_OPTIONS} --upgrade pip if pip install ${PIP_OPTIONS} -r /tmp/App/requirements.txt; then echo "安装依赖成功" frontend_version=$(curl ${CURL_OPTIONS} "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases/latest" ${CURL_HEADERS} | jq -r .tag_name) if [[ "${frontend_version}" == *v* ]]; then - if download_and_unzip "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${frontend_version}/dist.zip" "dist"; then + if download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot-Frontend/releases/download/${frontend_version}/dist.zip" "dist"; then echo "前端程序下载成功" # 提前备份插件目录 rm -rf /plugins @@ -49,7 +49,7 @@ install_backend_and_download_resources() { rm -rf /tmp/* echo "程序部分更新成功,前端版本:${frontend_version},后端版本:${1}"s echo "开始更新插件..." - if download_and_unzip "https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip" "Plugins"; then + if download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot-Plugins/archive/refs/heads/main.zip" "Plugins"; then echo "插件下载成功" # 恢复插件目录 cp -a /plugins/* /app/app/plugins/ @@ -61,7 +61,7 @@ install_backend_and_download_resources() { rm -rf /tmp/* echo "插件更新成功" echo "开始更新资源包..." - if download_and_unzip "https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" "Resources"; then + if download_and_unzip "${GITHUB_PROXY}https://github.com/jxxghp/MoviePilot-Resources/archive/refs/heads/main.zip" "Resources"; then echo "资源包下载成功" # 资源包 cp -a /tmp/Resources/resources/* /app/app/helper/