Skip to content

Commit

Permalink
#58 补回gh proxy的代理
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Dec 25, 2023
1 parent cedda91 commit 79f809a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/gui/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from basic import os_utils
from basic.log_utils import log
from sr.const.game_config_const import GH_PROXY_URL


@lru_cache
Expand All @@ -37,17 +38,20 @@ def get_latest_release_info(proxy: Optional[str] = None, pre_release: bool = Fal
"""
log.info('正在获取最新版本信息')

proxy_to_use = None if proxy == GH_PROXY_URL else proxy
proxies = {'http': proxy_to_use, 'https': proxy_to_use} if proxy_to_use is not None else None

if pre_release: # 获取pre-release
url = 'https://api.github.com/repos/DoctorReid/StarRailAutoProxy/releases'
response = requests.get(url, proxies={'http': proxy, 'https': proxy} if proxy is not None else None)
response = requests.get(url, proxies=proxies)
if response.status_code != 200:
log.error('获取最新版本信息失败 %s', response.content)
return None
else:
return response.json()[0]
else: # 获取最新release信息
url = 'https://api.github.com/repos/DoctorReid/StarRailAutoProxy/releases/latest'
response = requests.get(url, proxies={'http': proxy, 'https': proxy} if proxy is not None else None)
response = requests.get(url, proxies=proxies)
if response.status_code != 200:
log.error('获取最新版本信息失败 %s', response.content)
return None
Expand Down
2 changes: 1 addition & 1 deletion src/sr/config/game_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def proxy_address(self) -> Optional[str]:
if proxy_type == game_config_const.PROXY_TYPE_NONE.id:
return None
elif proxy_type == game_config_const.PROXY_TYPE_GHPROXY.id:
return 'https://gh-proxy.com/'
return game_config_const.GH_PROXY_URL
elif proxy_type == game_config_const.PROXY_TYPE_PERSONAL.id:
proxy = self.personal_proxy
return None if proxy == '' else proxy
Expand Down
6 changes: 4 additions & 2 deletions src/sr/const/game_config_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def __init__(self, id: str, cn: str):

PROXY_TYPE_NONE = ProxyType(id='none', cn='无')
PROXY_TYPE_PERSONAL = ProxyType(id='personal', cn='个人代理')
PROXY_TYPE_GHPROXY = ProxyType(id='ghproxy', cn='gh-proxy') # 似乎失效了
PROXY_TYPE_GHPROXY = ProxyType(id='ghproxy', cn='ghproxy') # 似乎失效了

PROXY_TYPE_LIST: List[ProxyType] = [PROXY_TYPE_NONE, PROXY_TYPE_PERSONAL,]
PROXY_TYPE_LIST: List[ProxyType] = [PROXY_TYPE_NONE, PROXY_TYPE_PERSONAL, PROXY_TYPE_GHPROXY]

GH_PROXY_URL = 'https://mirror.ghproxy.com/'
2 changes: 1 addition & 1 deletion version.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version: "v0.8.5"
version: "v0.8.6"

0 comments on commit 79f809a

Please sign in to comment.