43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""代理模块使用的白名单适配器。"""
|
|
|
|
from typing import Optional
|
|
|
|
from .proxy_platforms import create_adapter
|
|
from .proxy_platforms.base import BaseWhitelistAdapter, _get_local_exit_ip
|
|
|
|
|
|
class DouyuWhitelistSyncer:
|
|
"""把白名单 API 隔离成代理解析流程可调用的适配器。
|
|
|
|
支持:
|
|
- 新接口: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]:
|
|
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()
|