feat 增加GITHUB_TOKEN,提高API限流阈值

This commit is contained in:
thsrite
2023-11-14 16:12:02 +08:00
parent f514a5a416
commit 0aad809c82
6 changed files with 29 additions and 5 deletions

View File

@@ -163,7 +163,13 @@ def latest_version(_: schemas.TokenPayload = Depends(verify_token)):
"""
查询Github所有Release版本
"""
version_res = RequestUtils().get_res(f"https://api.github.com/repos/jxxghp/MoviePilot/releases")
headers = {}
if settings.GITHUB_TOKEN:
headers = {
"Authorization": f"Bearer {settings.GITHUB_TOKEN}"
}
version_res = RequestUtils(proxies=settings.PROXY, headers=headers).get_res(
f"https://api.github.com/repos/jxxghp/MoviePilot/releases")
if version_res:
ver_json = version_res.json()
if ver_json:

View File

@@ -87,7 +87,12 @@ class SystemChain(ChainBase, metaclass=Singleton):
"""
获取最新版本
"""
version_res = RequestUtils(proxies=settings.PROXY).get_res(
headers = {}
if settings.GITHUB_TOKEN:
headers = {
"Authorization": f"Bearer {settings.GITHUB_TOKEN}"
}
version_res = RequestUtils(proxies=settings.PROXY, headers=headers).get_res(
"https://api.github.com/repos/jxxghp/MoviePilot/releases/latest")
if version_res:
ver_json = version_res.json()

View File

@@ -212,6 +212,8 @@ class Settings(BaseSettings):
BIG_MEMORY_MODE: bool = False
# 插件市场仓库地址,多个地址使用,分隔,地址以/结尾
PLUGIN_MARKET: str = "https://raw.githubusercontent.com/jxxghp/MoviePilot-Plugins/main/"
# Github token提高请求api限流阈值 ghp_****
GITHUB_TOKEN: str = None
@property
def INNER_CONFIG_PATH(self):

View File

@@ -49,7 +49,12 @@ class PluginHelper(metaclass=Singleton):
获取插件的文件列表
"""
file_api = f"https://api.github.com/repos/{user}/{repo}/contents/plugins/{_p.lower()}"
r = RequestUtils(proxies=settings.PROXY).get_res(file_api)
headers = {}
if settings.GITHUB_TOKEN:
headers = {
"Authorization": f"Bearer {settings.GITHUB_TOKEN}"
}
r = RequestUtils(proxies=settings.PROXY, headers=headers).get_res(file_api)
if not r or r.status_code != 200:
return None, f"连接仓库失败:{r.status_code} - {r.reason}"
ret = r.json()