This commit is contained in:
ricterzheng 2025-01-28 17:43:50 +08:00
parent 5ad416efa6
commit 58b5ec4211
4 changed files with 9 additions and 9 deletions

View File

@ -189,10 +189,7 @@ def cmd_parser():
logger.error(f'Invalid protocol "{proxy_url.scheme}" of proxy, ignored') logger.error(f'Invalid protocol "{proxy_url.scheme}" of proxy, ignored')
sys.exit(0) sys.exit(0)
else: else:
constant.CONFIG['proxy'] = { constant.CONFIG['proxy'] = args.proxy
'http': args.proxy,
'https': args.proxy,
}
logger.info(f'Proxy now set to "{args.proxy}"') logger.info(f'Proxy now set to "{args.proxy}"')
write_config() write_config()
sys.exit(0) sys.exit(0)

View File

@ -28,8 +28,8 @@ def main():
logger.info(f'Using mirror: {BASE_URL}') logger.info(f'Using mirror: {BASE_URL}')
# CONFIG['proxy'] will be changed after cmd_parser() # CONFIG['proxy'] will be changed after cmd_parser()
if constant.CONFIG['proxy']['http']: if constant.CONFIG['proxy']:
logger.info(f'Using proxy: {constant.CONFIG["proxy"]["http"]}') logger.info(f'Using proxy: {constant.CONFIG["proxy"]}')
if not constant.CONFIG['template']: if not constant.CONFIG['template']:
constant.CONFIG['template'] = 'default' constant.CONFIG['template'] = 'default'

View File

@ -55,7 +55,7 @@ NHENTAI_CONFIG_FILE = os.path.join(NHENTAI_HOME, 'config.json')
__api_suspended_DETAIL_URL = f'{BASE_URL}/api/gallery' __api_suspended_DETAIL_URL = f'{BASE_URL}/api/gallery'
CONFIG = { CONFIG = {
'proxy': {'http': '', 'https': ''}, 'proxy': '',
'cookie': '', 'cookie': '',
'language': '', 'language': '',
'template': '', 'template': '',

View File

@ -31,7 +31,10 @@ def request(method, url, **kwargs):
}) })
if not kwargs.get('proxies', None): 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) return getattr(session, method)(url, verify=False, **kwargs)
@ -46,7 +49,7 @@ async def async_request(method, url, proxy = None, **kwargs):
if proxy is None: if proxy is None:
proxy = constant.CONFIG['proxy'] 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 proxy = None
async with httpx.AsyncClient(headers=headers, verify=False, proxy=proxy, **kwargs) as client: async with httpx.AsyncClient(headers=headers, verify=False, proxy=proxy, **kwargs) as client: