mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: 为GitHub API的访问使用代理 (#312)
This commit is contained in:
parent
1964fc76c8
commit
d2a7a57245
|
@ -46,7 +46,7 @@ class DataGatherer:
|
||||||
config = pkg.utils.context.get_config()
|
config = pkg.utils.context.get_config()
|
||||||
if hasattr(config, "report_usage") and not config.report_usage:
|
if hasattr(config, "report_usage") and not config.report_usage:
|
||||||
return
|
return
|
||||||
res = requests.get("http://rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, self.version_str, count))
|
res = requests.get("http://reports.rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, self.version_str, count))
|
||||||
if res.status_code != 200 or res.text != "ok":
|
if res.status_code != 200 or res.text != "ok":
|
||||||
logging.warning("report to server failed, status_code: {}, text: {}".format(res.status_code, res.text))
|
logging.warning("report to server failed, status_code: {}, text: {}".format(res.status_code, res.text))
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -3,10 +3,13 @@ import os
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import pkg.utils.network as network
|
||||||
|
|
||||||
|
|
||||||
def read_latest() -> str:
|
def read_latest() -> str:
|
||||||
resp = requests.get(
|
resp = requests.get(
|
||||||
url="https://api.github.com/repos/RockChinQ/QChatGPT/contents/res/announcement",
|
url="https://api.github.com/repos/RockChinQ/QChatGPT/contents/res/announcement",
|
||||||
|
proxies=network.wrapper_proxies()
|
||||||
)
|
)
|
||||||
obj_json = resp.json()
|
obj_json = resp.json()
|
||||||
b64_content = obj_json["content"]
|
b64_content = obj_json["content"]
|
||||||
|
|
9
pkg/utils/network.py
Normal file
9
pkg/utils/network.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
def wrapper_proxies() -> dict:
|
||||||
|
"""获取代理"""
|
||||||
|
import config
|
||||||
|
|
||||||
|
return {
|
||||||
|
"http": config.openai_config['proxy'],
|
||||||
|
"https": config.openai_config['proxy']
|
||||||
|
} if 'proxy' in config.openai_config and (config.openai_config['proxy'] is not None) else None
|
|
@ -6,6 +6,7 @@ import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pkg.utils.constants
|
import pkg.utils.constants
|
||||||
|
import pkg.utils.network as network
|
||||||
|
|
||||||
|
|
||||||
def check_dulwich_closure():
|
def check_dulwich_closure():
|
||||||
|
@ -36,7 +37,8 @@ def pull_latest(repo_path: str) -> bool:
|
||||||
def get_release_list() -> list:
|
def get_release_list() -> list:
|
||||||
"""获取发行列表"""
|
"""获取发行列表"""
|
||||||
rls_list_resp = requests.get(
|
rls_list_resp = requests.get(
|
||||||
url="https://api.github.com/repos/RockChinQ/QChatGPT/releases"
|
url="https://api.github.com/repos/RockChinQ/QChatGPT/releases",
|
||||||
|
proxies=network.wrapper_proxies()
|
||||||
)
|
)
|
||||||
|
|
||||||
rls_list = rls_list_resp.json()
|
rls_list = rls_list_resp.json()
|
||||||
|
@ -83,7 +85,10 @@ def update_all(cli: bool = False) -> bool:
|
||||||
else:
|
else:
|
||||||
print("开始下载最新版本: {}".format(latest_rls['zipball_url']))
|
print("开始下载最新版本: {}".format(latest_rls['zipball_url']))
|
||||||
zip_url = latest_rls['zipball_url']
|
zip_url = latest_rls['zipball_url']
|
||||||
zip_resp = requests.get(url=zip_url)
|
zip_resp = requests.get(
|
||||||
|
url=zip_url,
|
||||||
|
proxies=network.wrapper_proxies()
|
||||||
|
)
|
||||||
zip_data = zip_resp.content
|
zip_data = zip_resp.content
|
||||||
|
|
||||||
# 检查temp/updater目录
|
# 检查temp/updater目录
|
||||||
|
|
Loading…
Reference in New Issue
Block a user