Skip to content

Commit

Permalink
fix: disable bypass mode temporarily
Browse files Browse the repository at this point in the history
- 暂时 停用 Bypass 模式
  • Loading branch information
txperl committed Oct 31, 2024
1 parent 6b6ea8d commit e731dd4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 37 deletions.
92 changes: 55 additions & 37 deletions app/lib/common/login_helper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,73 @@ def __init__(self):

def check_network(self, is_no_proxy: bool = False, is_silent: bool = False):
"""
网络检测。筛选出本机可通的 Pixiv API 服务器。
网络检测,并筛选出本机可通的 Pixiv API 服务器。
:param URLS: 全部 URL
:param silent: 是否静默进行
:param proxy_: 代理设置,auto 为程序自动判断
:return: bool
"""
# Determine the final proxy address, or empty
self.proxy = "" if is_no_proxy else self._determine_proxy(is_silent=is_silent)
if is_no_proxy:
return self._test_pixiv_connection(proxy="")

is_pixiv_accessible = True

# Determine the proxy address, or empty
proxy = self.STATIC.util.get_system_proxy()
if proxy != "" and self._test_pixiv_connection(proxy=proxy):
pass
elif self._test_pixiv_connection(proxy=""):
proxy = ""
elif is_silent is False:
# Require to set proxy manually
if input(
self.lang("network.hint_detect_proxy") % proxy
if proxy
else self.lang("network.is_need_to_type_proxy")
) in ["y", ""]:
proxy = input(self.lang("network.press_need_to_type_proxy"))
is_pixiv_accessible = self._test_pixiv_connection(proxy=proxy)

# For now, the bypass mode is disabled
self.proxy = proxy
self.auth_token_url = self.SOME_URLS[0]

if not is_silent:
_ln(
(
SPrint.green("- Pixiv.net, Yep!")
if is_pixiv_accessible
else SPrint.red("- Pixiv.net, Ops...")
),
header=None,
)

return is_pixiv_accessible

# Determine the final auth host
# Check if the hosts are accessible
is_conn_array = [
self._test_access(url=url, proxy=self.proxy, is_silent=False)
for url in self.SOME_URLS
]
# is_conn_array = [
# self._test_access(url=url, proxy=self.proxy, is_silent=False)
# for url in self.SOME_URLS
# ]

# If Pixiv is accessible, just use the official
if is_conn_array[0]:
self.auth_token_url = self.SOME_URLS[0]
return True
# if is_conn_array[0]:
# self.auth_token_url = self.SOME_URLS[0]
# return True

# Or, get the real ip of auth service from DoH service to bypass SNI
for i in range(len(self.SOME_URLS)):
if is_conn_array[i] is False:
continue
final_ip = self._get_host_ip(
hostname=self.SOME_URLS[0], url=self.SOME_URLS[i]
)
if final_ip is not False:
self.auth_token_url = final_ip
return True

return False
# for i in range(len(self.SOME_URLS)):
# if is_conn_array[i] is False:
# continue
# final_ip = self._get_host_ip(
# hostname=self.SOME_URLS[0], url=self.SOME_URLS[i]
# )
# if final_ip is not False:
# self.auth_token_url = final_ip
# return True

# return False

def login(self):
"""
Expand Down Expand Up @@ -144,22 +178,6 @@ def get_proxy(self) -> str:
def is_bypass(self) -> bool:
return self.auth_token_url != self.SOME_URLS[0]

def _determine_proxy(self, is_silent: bool = False) -> str:
proxy = self.STATIC.util.get_system_proxy()
if proxy != "" and self._test_pixiv_connection(proxy=proxy):
pass
elif self._test_pixiv_connection(proxy=""):
proxy = ""
elif is_silent is False:
# Require to set proxy manually
if input(
self.lang("network.hint_detect_proxy") % proxy
if proxy
else self.lang("network.is_need_to_type_proxy")
) in ["y", ""]:
proxy = input(self.lang("network.press_need_to_type_proxy"))
return proxy

@classmethod
def _test_access(cls, url: str, proxy: str = "", is_silent: bool = False):
"""
Expand Down
1 change: 1 addition & 0 deletions app/lib/core/biu.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def __login_app_api(
"""
app 模式登录。
"""
self.api_route = "direct"
if self.api is None:
_REQUESTS_KWARGS = {}
if self.proxy != "":
Expand Down

0 comments on commit e731dd4

Please sign in to comment.