fix(web): up list search matches up name only, not video titles

This commit is contained in:
kairee committed 2026-11-01 17:57:34 +08:00
1 parent a6bd910d9d
commit 003e65086e
2 files changed
+26 -2

No files matched your search

+13 -2
View File
@@ -46,6 +46,8 @@ UP_SORTS = {
"views", "count", "avg_views", "interaction", "avg_interaction", "latest",
"efficiency", "interaction_efficiency", "duration",
}
# 搜索字段白名单:视频搜索匹配标题或 UP 名,UP 搜索只匹配 UP 名。
_Q_FIELDS = {"title": "v.title", "up_name": "v.up_name"}
CAPACITY = 1000
CAPACITY_WARNING = 950
TRACK_FANS_NAMES = {37754047: "咻咻满"}
@@ -284,6 +286,7 @@ class DashboardQueries:
statuses: Sequence[str] = TRACKED_STATUSES,
folder_id: int | None = None,
q: str | None = None,
q_fields: Sequence[str] | None = None,
within_field: str | None = None,
within_start: str | None = None,
within_end: str | None = None,
@@ -299,10 +302,17 @@ class DashboardQueries:
params.append(int(up_mid))
if q:
pattern = _like_pattern(q)
fields = tuple(q_fields) if q_fields else ("title", "up_name")
columns = []
for field in fields:
column = _Q_FIELDS.get(field)
if column is None:
raise ValueError(f"不支持的搜索字段: {field}")
columns.append(column)
clauses.append(
"(v.title LIKE ? ESCAPE '\\' OR v.up_name LIKE ? ESCAPE '\\')"
"(" + " OR ".join(f"{col} LIKE ? ESCAPE '\\'" for col in columns) + ")"
)
params.extend([pattern, pattern])
params.extend([pattern] * len(columns))
if within_field:
if within_field not in {"pubdate", "first_seen"}:
raise ValueError("within_field 必须是 pubdate 或 first_seen")
@@ -1060,6 +1070,7 @@ class DashboardQueries:
videos = self._videos(
conn,
q=q,
q_fields=("up_name",) if q else None,
within_field=within_field,
within_start=within_start,
within_end=within_end,