增加了代理平台和日志
This commit is contained in:
@@ -2,19 +2,41 @@
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from .whitelist import WhitelistManager, get_local_exit_ip
|
||||
from .proxy_platforms import create_adapter
|
||||
from .proxy_platforms.base import BaseWhitelistAdapter, _get_local_exit_ip
|
||||
|
||||
|
||||
class DouyuWhitelistSyncer:
|
||||
"""把白名单 API 隔离成代理解析流程可调用的适配器。"""
|
||||
"""把白名单 API 隔离成代理解析流程可调用的适配器。
|
||||
|
||||
def __init__(self, uid: str, ukey: str):
|
||||
self.uid = uid
|
||||
self.ukey = ukey
|
||||
支持:
|
||||
- 新接口:platform + credentials(推荐)
|
||||
- 旧接口:uid + ukey(向后兼容,自动映射为协固平台)
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
platform: str = "xiequ",
|
||||
credentials: dict = None,
|
||||
uid: str = "",
|
||||
ukey: str = "",
|
||||
):
|
||||
# 向后兼容:如果传入 uid/ukey,转为 credentials
|
||||
if uid and ukey and not credentials:
|
||||
platform = "xiequ"
|
||||
credentials = {"uid": uid, "ukey": ukey}
|
||||
|
||||
self.platform = platform
|
||||
self.credentials = credentials or {}
|
||||
self._adapter: Optional[BaseWhitelistAdapter] = None
|
||||
|
||||
if self.credentials:
|
||||
self._adapter = create_adapter(platform, self.credentials)
|
||||
|
||||
def sync_ip(self, ip: str) -> tuple[bool, str]:
|
||||
manager = WhitelistManager(self.uid, self.ukey)
|
||||
return manager.sync_ip(ip)
|
||||
if not self._adapter:
|
||||
return False, "未配置白名单凭据"
|
||||
return self._adapter.sync_ip(ip)
|
||||
|
||||
def get_local_exit_ip(self) -> Optional[str]:
|
||||
return get_local_exit_ip()
|
||||
return _get_local_exit_ip()
|
||||
|
||||
Reference in New Issue
Block a user