perf: 优化qb下载器端口获取逻辑

This commit is contained in:
Dee Luo
2025-04-11 15:43:40 +08:00
committed by GitHub
parent 86e1f9a9d6
commit 8ca4ea0f3f
+7 -6
View File
@@ -642,13 +642,14 @@ class StringUtils:
if len(parts) > 3: if len(parts) > 3:
# 处理不希望包含多个冒号的情况(除了协议后的冒号) # 处理不希望包含多个冒号的情况(除了协议后的冒号)
return None, None return None, None
# 不含端口地址 elif len(parts) == 3:
domain = ":".join(parts[:-1]).rstrip('/')
# 端口号
try:
port = int(parts[-1]) port = int(parts[-1])
except ValueError: # 不含端口地址
# 端口号不是整数,返回 None 表示无效 domain = ":".join(parts[:-1]).rstrip('/')
elif len(parts) == 2:
port = 443 if address.startswith("https") else 80
domain = address
else:
return None, None return None, None
return domain, port return domain, port