Refactor IP location check and update HTTP client config

Moved the IP location check logic to constants.py and set IS_CN at import time, removing the async check_ip method from OnekeyApp. Updated all httpx client instantiations to use verify=False for SSL verification. Adjusted imports and usages accordingly in web/app.py and main.py.
This commit is contained in:
ikun0014
2025-09-20 18:55:49 +08:00
parent 1a6cf47882
commit 2a6a9421ca
4 changed files with 25 additions and 13 deletions

View File

@@ -1,12 +1,30 @@
"""常量定义"""
from pathlib import Path
from httpx import Client
LOG_DIR: Path = Path("logs")
IS_CN: bool = True
CONFIG_FILE: Path = Path("config.json")
def check_ip():
try:
with Client(verify=False, timeout=5.0) as client:
req = client.get(
"https://mips.kugou.com/check/iscn",
)
req.raise_for_status()
body = req.json()
print("已获取IP属地")
return bool(body["flag"])
except:
print("获取IP属地失败, 默认您位于中国大陆境内")
return True
IS_CN: bool = check_ip()
STEAM_API_BASE: str = "https://steam.ikunshare.com/api"
STEAM_CACHE_CDN_LIST: list = (
[

View File

@@ -5,7 +5,6 @@ from .logger import Logger
from .models import DepotInfo, ManifestInfo, SteamAppInfo, SteamAppManifestInfo
from .network.client import HttpClient
from .manifest_handler import ManifestHandler
from . import constants
class OnekeyApp:
@@ -20,14 +19,6 @@ class OnekeyApp:
)
self.client = HttpClient()
async def check_ip(self):
req = await self.client.get(
"https://mips.kugou.com/check/iscn",
)
req.raise_for_status()
body = req.json()
constants.IS_CN = bool(body["flag"])
async def fetch_key(self):
trans = {
"week": "周卡",
@@ -165,7 +156,6 @@ class OnekeyApp:
self.logger.error("Steam路径未配置或无效无法继续")
return False
await self.check_ip()
await self.fetch_key()
manifests = []

View File

@@ -8,7 +8,7 @@ class HttpClient:
"""HTTP客户端封装"""
def __init__(self):
self._client = httpx.AsyncClient(timeout=60)
self._client = httpx.AsyncClient(timeout=60.0, verify=False)
async def get(self, url: str, headers: Optional[Dict] = None) -> httpx.Response:
"""GET请求"""

View File

@@ -13,6 +13,7 @@ from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, RedirectResponse
from fastapi.templating import Jinja2Templates
from src import constants
from src.constants import STEAM_API_BASE
@@ -205,6 +206,9 @@ templates = Jinja2Templates(directory=f"{base_path}/templates")
web_app = WebOnekeyApp(manager)
@app.get("/")
async def index(request: Request):
"""主页"""
@@ -391,7 +395,7 @@ async def get_key_info(request: Request):
if not key:
return JSONResponse({"success": False, "message": "卡密不能为空"})
async with httpx.AsyncClient(timeout=10.0) as client:
async with httpx.AsyncClient(timeout=10.0, verify=False) as client:
response = await client.post(
f"{STEAM_API_BASE}/getKeyInfo",
json={"key": key},