Skip to content

Commit

Permalink
fix #382
Browse files Browse the repository at this point in the history
  • Loading branch information
ricterzheng committed Jan 28, 2025
1 parent 5ad416e commit 58b5ec4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
5 changes: 1 addition & 4 deletions nhentai/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ def cmd_parser():
logger.error(f'Invalid protocol "{proxy_url.scheme}" of proxy, ignored')
sys.exit(0)
else:
constant.CONFIG['proxy'] = {
'http': args.proxy,
'https': args.proxy,
}
constant.CONFIG['proxy'] = args.proxy
logger.info(f'Proxy now set to "{args.proxy}"')
write_config()
sys.exit(0)
Expand Down
4 changes: 2 additions & 2 deletions nhentai/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def main():
logger.info(f'Using mirror: {BASE_URL}')

# CONFIG['proxy'] will be changed after cmd_parser()
if constant.CONFIG['proxy']['http']:
logger.info(f'Using proxy: {constant.CONFIG["proxy"]["http"]}')
if constant.CONFIG['proxy']:
logger.info(f'Using proxy: {constant.CONFIG["proxy"]}')

if not constant.CONFIG['template']:
constant.CONFIG['template'] = 'default'
Expand Down
2 changes: 1 addition & 1 deletion nhentai/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_nhentai_home() -> str:
__api_suspended_DETAIL_URL = f'{BASE_URL}/api/gallery'

CONFIG = {
'proxy': {'http': '', 'https': ''},
'proxy': '',
'cookie': '',
'language': '',
'template': '',
Expand Down
7 changes: 5 additions & 2 deletions nhentai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def request(method, url, **kwargs):
})

if not kwargs.get('proxies', None):
kwargs['proxies'] = constant.CONFIG['proxy']
kwargs['proxies'] = {
'https': constant.CONFIG['proxy'],
'http': constant.CONFIG['proxy'],
}

return getattr(session, method)(url, verify=False, **kwargs)

Expand All @@ -46,7 +49,7 @@ async def async_request(method, url, proxy = None, **kwargs):
if proxy is None:
proxy = constant.CONFIG['proxy']

if proxy is not None and proxy.get('http') == '' and proxy.get('https') == '':
if isinstance(proxy, (str, )) and not proxy:
proxy = None

async with httpx.AsyncClient(headers=headers, verify=False, proxy=proxy, **kwargs) as client:
Expand Down

0 comments on commit 58b5ec4

Please sign in to comment.