mirror of
https://github.com/ikunshare/Onekey.git
synced 2026-01-12 16:25:53 +08:00
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:
@@ -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 = (
|
||||
[
|
||||
|
||||
10
src/main.py
10
src/main.py
@@ -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 = []
|
||||
|
||||
@@ -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请求"""
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user