feat: add init with host resolution and search verify check

Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
Harold
2026-04-20 13:00:04 +08:00
co-authored by Claude Opus 4.7
parent f190f770c4
commit d76fe86f3a
2 changed files with 36 additions and 1 deletions
+15
View File
@@ -38,3 +38,18 @@ class TestJingyuSpider(unittest.TestCase):
self.spider.host = "http://test.com"
result = self.spider._api_post("someEndpoint")
self.assertEqual(result, payload)
def test_init_fetches_host_from_site_url(self):
init_encrypted = self.spider._aes_encrypt(json.dumps({"type_list": []}))
class FakeInitResponse:
status_code = 200
encoding = "utf-8"
text = "http://example.com"
def json(self):
return {"data": init_encrypted}
self.spider.fetch = lambda url, **kwargs: FakeInitResponse()
self.spider.post = lambda url, **kwargs: FakeInitResponse()
self.spider.init()
self.assertEqual(self.spider.host, "http://example.com")
+21 -1
View File
@@ -29,8 +29,28 @@ class Spider(BaseSpider):
def getName(self):
return self.name
SITE_URL = "https://jingyu4k-1312635929.cos.ap-nanjing.myqcloud.com/juyu3.json"
def init(self, extend=""):
pass
if self.host:
return
headers = {"User-Agent": self.ua}
try:
rsp = self.fetch(self.SITE_URL, headers=headers, timeout=10, verify=False)
host = rsp.text.strip().rstrip("/")
if not host.startswith("http"):
host = "http://" + host
self.host = host
except Exception as e:
self.log(f"获取host失败: {e}")
raise
try:
data = self._api_post(self.init_endpoint)
if data and data.get("config", {}).get("system_search_verify_status"):
self.search_verify = True
self.init_data = data
except Exception as e:
self.log(f"初始化数据失败: {e}")
def _aes_encrypt(self, plaintext):
key = AES_KEY.encode("utf-8")