fix(home): server-owned growth window; expose days

Home omits growth_days; backend auto (or home_growth_days 1/7) picks
the window. Response includes days alongside growth_days. Growth榜 link
uses the returned days. Non-growth sorts treat omitted/auto as 7.
This commit is contained in:
bot-ci committed 2026-11-02 10:05:00 +08:00
1 parent 9163f47b76
commit 297d9279d8
5 files changed
+52 -28

No files matched your search

+25 -18
View File
@@ -699,7 +699,7 @@ class DashboardQueries:
sort: str = "heat",
within_days: int | None = None,
year: int | None = None,
growth_days: int | str = 7,
growth_days: int | str = "auto",
folder_id: int | None = None,
q: str | None = None,
page: int = 1,
@@ -734,7 +734,7 @@ class DashboardQueries:
sort: str = "heat",
within_days: int | None = None,
year: int | None = None,
growth_days: int | str = 7,
growth_days: int | str = "auto",
folder_id: int | None = None,
q: str | None = None,
page: int = 1,
@@ -742,24 +742,29 @@ class DashboardQueries:
) -> dict[str, Any]:
if sort not in VIDEO_SORTS:
raise ValueError(f"不支持的排序: {sort}")
# auto:仅增长类排序由服务端选窗(配置 home_growth_days;默认先 7 再降 1)。
# 首页应省略 growth_days,勿自行探查。其它排序把 auto 当作 7(兼容旧默认)。
if growth_days == "auto":
preferred = self.config_store.get().analytics.home_growth_days
if preferred in (1, 7):
growth_days = int(preferred)
if sort in {"growth", "growth_rate"}:
preferred = self.config_store.get().analytics.home_growth_days
if preferred in (1, 7):
growth_days = int(preferred)
else:
trial = self._list_videos_uncached(
sort=sort,
within_days=within_days,
year=year,
growth_days=7,
folder_id=folder_id,
q=q,
page=page,
page_size=page_size,
)
if trial.get("available") and int(trial.get("total") or 0) > 0:
return trial
growth_days = 1
else:
trial = self._list_videos_uncached(
sort=sort,
within_days=within_days,
year=year,
growth_days=7,
folder_id=folder_id,
q=q,
page=page,
page_size=page_size,
)
if trial.get("available") and int(trial.get("total") or 0) > 0:
return trial
growth_days = 1
growth_days = 7
growth_days = int(growth_days)
if growth_days < 1 or growth_days > 365:
raise ValueError("growth_days 必须在 1~365 之间")
@@ -942,6 +947,8 @@ class DashboardQueries:
"within_days": within_days,
"year": year,
"growth_days": growth_days,
# days:与 growth_days 同步;首页 auto 时为 1|7,供前端链接/展示
"days": growth_days,
"page": page,
"page_size": page_size,
"total": total,
+3 -4
View File
@@ -650,11 +650,10 @@ def _year_param(query: Mapping[str, list[str]]) -> int | None:
def _growth_days_param(query: Mapping[str, list[str]]) -> int | str:
"""榜单传 1~365;首页可传 auto(由查询层按 home_growth_days 解析)。"""
"""省略或 auto:查询层按 home_growth_days 解析(默认 7→1)。
榜单应显式传 1~365。"""
raw = _optional_str(query, "growth_days")
if raw is None:
return 7
if raw == "auto":
if raw is None or raw == "auto":
return "auto"
try:
value = int(raw)
+4 -3
View File
@@ -47,8 +47,8 @@ export async function renderHome(root) {
api("/api/overview"),
api("/api/videos", { sort: "published", within_days: 14, limit: 6 }),
api("/api/videos", { sort: "heat", limit: 6 }),
// auto:服务端按 analytics.home_growth_days 解析;默认先试 7 天再降到 1 天
api("/api/videos", { sort: "growth", growth_days: "auto", limit: 6 }),
// 不带天数:后端按 home_growth_days(默认 auto:有 7 日则 7,否则 1)决定,响应带 days
api("/api/videos", { sort: "growth", limit: 6 }),
]);
const fans = overview.fans;
@@ -60,7 +60,8 @@ export async function renderHome(root) {
const pending = overview.counts?.candidates_pending || 0;
// 候选提示仅对已登录(或未启用鉴权)用户可见,访客不展示运行期信息。
const showCandidates = pending > 0 && canAccessProtected();
const growthDays = Number(growth.growth_days) || 1;
// 以后端返回的 days(与 growth_days 同步)为准,避免前端再探查
const growthDays = Number(growth.days ?? growth.growth_days) || 1;
const growthLabel = `近 ${growthDays} 日`;
const growthEmptyTitle = growth.reason
|| `近 ${growthDays} 日增长暂不可用`;