fix(site): recognize Gazelle login state (#6464)

This commit is contained in:
jxxghp
2026-08-26 21:09:19 +08:00
parent 88703d645a
commit 0a5b6a637d
2 changed files with 45 additions and 0 deletions
+21
View File
@@ -12,8 +12,29 @@ from app.modules.indexer.parser import SiteParserBase, SiteSchema
class GazelleSiteUserInfo(SiteParserBase): class GazelleSiteUserInfo(SiteParserBase):
"""Gazelle 站点用户数据解析器。"""
schema = SiteSchema.Gazelle schema = SiteSchema.Gazelle
def _parse_logged_in(self, html_text: str) -> bool:
"""
识别 Gazelle 登录态,兼容不展示退出入口的站点首页。
:param html_text: 站点首页 HTML
:return: 已登录返回 True,否则返回 False
"""
html = etree.HTML(html_text)
try:
if DomUtils.has_child_elements(html) and html.xpath(
'//a[contains(@href, "user.php?id=")]'
):
return True
finally:
if html is not None:
del html
return super()._parse_logged_in(html_text)
def _parse_user_base_info(self, html_text: str): def _parse_user_base_info(self, html_text: str):
html_text = self._prepare_html_text(html_text) html_text = self._prepare_html_text(html_text)
html = etree.HTML(html_text) html = etree.HTML(html_text)
+24
View File
@@ -179,3 +179,27 @@ def test_gazelle_seeding_keeps_legacy_column_fallback():
assert parser.seeding == 1 assert parser.seeding == 1
assert parser.seeding_size == 2147483648 assert parser.seeding_size == 2147483648
assert parser.seeding_info == [[45, 2147483648]] assert parser.seeding_info == [[45, 2147483648]]
def test_gazelle_login_accepts_current_user_link_without_logout_marker():
"""Gazelle 首页仅暴露当前用户链接时也应识别为已登录。"""
parser = _build_parser()
logged_in_html = (
'<html><body><a href="user.php?id=1234">tester</a>'
'<a href="bonus.php">积分 (42.0)</a></body></html>'
)
assert parser._parse_logged_in(logged_in_html) is True
assert parser.err_msg is None
def test_gazelle_login_rejects_password_form_without_current_user_link():
"""Gazelle 登录页不得因普通用户相关文本被误判为已登录。"""
parser = _build_parser()
login_html = (
'<html><body><form action="login.php">'
'<input type="password" name="password"></form></body></html>'
)
assert parser._parse_logged_in(login_html) is False
assert parser.err_msg == "未检测到已登陆,请检查cookies是否过期"