Skip to content

Commit

Permalink
Fix 更新公共模板时 Proxies 配置无效
Browse files Browse the repository at this point in the history
Fix #412
  • Loading branch information
a76yyyy committed May 18, 2023
1 parent 9e38fbb commit dadca07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions libs/parse_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ def parse_url(url):
'port': int(result.group('port')),
'username': result.group('username'),
'password': result.group('password'),
'href': str(url)
}
12 changes: 8 additions & 4 deletions web/handlers/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ async def post(self, userid):
repos = json.loads((await self.db.site.get(1, fields=('repos',), sql_session=sql_session))['repos'])
if proxies:
proxy = random.choice(proxies)
if proxy.get("href"):
proxy = proxy["href"]
else:
proxy = None
else:
proxy = {}
proxy = None
# 如果上次更新时间大于1天则更新模板仓库
if (int(time.time()) - int(repos['lastupdate']) > 24 * 3600):
for repo in repos['repos']:
Expand All @@ -82,7 +86,7 @@ async def post(self, userid):

hfile_link = url + '/tpls_history.json'
async with aiohttp.ClientSession(conn_timeout=config.connect_timeout*5) as session:
async with session.get(hfile_link, verify_ssl=False, timeout=config.request_timeout) as res:
async with session.get(hfile_link, verify_ssl=False, timeout=config.request_timeout, proxy=proxy) as res:
if res.status == 200:
hfile = await res.json(content_type="")
logger_Web_Handler.info('200 Get repo {repo} history file success!'.format(repo=repo['reponame']))
Expand All @@ -100,7 +104,7 @@ async def post(self, userid):
if (int(tpl[0]['version']) < int(har['version'])):
if (har['content'] == ''):
har_url = "{0}/{1}".format(url, quote(har['filename']))
async with session.get(har_url, verify_ssl=False, timeout=config.request_timeout) as har_res:
async with session.get(har_url, verify_ssl=False, timeout=config.request_timeout, proxy=proxy) as har_res:
if har_res.status == 200:
har['content'] = base64.b64encode(await har_res.read()).decode()
else:
Expand All @@ -113,7 +117,7 @@ async def post(self, userid):
else:
if (har['content'] == ''):
har_url = "{0}/{1}".format(url, quote(har['filename']))
async with session.get(har_url, verify_ssl=False, timeout=config.request_timeout) as har_res:
async with session.get(har_url, verify_ssl=False, timeout=config.request_timeout, proxy=proxy) as har_res:
if har_res.status == 200:
har['content'] = base64.b64encode(await har_res.read()).decode()
else:
Expand Down

0 comments on commit dadca07

Please sign in to comment.