修复段评往下滑一直闪:评论接口分页改游标,页面还在按 page 翻页

上游评论页按 page=N 翻页,但列表接口 /para_review 早已改成游标分页(响应给
next_cursor,请求要带 cursor=)。接口不认识 page,于是每次「加载更多」都原样
返回第一页:一条新评论都加不进去,has_more 又始终是 true,评论页便一遍遍触发
加载更多、反复闪骨架屏——用户看到的就是段评往下滑一闪一闪,评论一条没多。

评论页是上游 HTML 改不了,于是在承载页面的接口代理里做最小适配:
  - 请求带 page=N(N>1)且有上一页给的游标时,换成 cursor= 请求;
  - 某页返回的 comment_id 全是已经见过的,就把 has_more 改成 false 收尾,
    避免页面在「加载更多 → 没有新内容」之间空转。

只认路径以 /para_review 结尾、带 page 且不带 cursor 的请求,其余原样透传。
This commit is contained in:
truewhile
2026-10-04 16:28:13 +08:00
parent d545ff1a7b
commit 6984158f24
3 changed files with 440 additions and 0 deletions
+14
View File
@@ -103,6 +103,9 @@ type pendingBrowser struct {
finalURL string
mode string
expires time.Time
// comments 段落评论接口的翻页适配(上游页面按 page 翻页,接口只认 cursor,
// 见 browser_comment_page.go)。
comments *commentPager
done chan struct{}
mu sync.Mutex
@@ -218,6 +221,7 @@ func (s *ReaderService) registerBrowser(ctx context.Context, sourceURL, sourceID
mode: mode,
expires: time.Now().Add(browserPageTTL),
done: make(chan struct{}),
comments: newCommentPager(),
}
s.browserMu.Lock()
@@ -511,6 +515,13 @@ func (s *ReaderService) ProxyBrowserXHR(ctx context.Context, id, method, target
if method == "" {
method = http.MethodGet
}
// 段落评论接口:评论页按 page=N 翻页,而接口只认 cursor(见
// browser_comment_page.go)。改写发生在补书源凭据之前,Cookie/Referer
// 仍然按目标站点选取。
pagerKey := ""
if entry.comments != nil {
target, pagerKey = entry.comments.rewriteRequest(target)
}
reqCtx, cancel := context.WithTimeout(ctx, browserFetchTimeout)
defer cancel()
// 挂上 sink:页面自己发起的请求(如扫码登录的轮询/取票跳转)下发的
@@ -577,6 +588,9 @@ func (s *ReaderService) ProxyBrowserXHR(ctx context.Context, id, method, target
out := &BrowserXHRResult{Status: resp.StatusCode, ContentType: contentType}
if isTextualContent(contentType) {
out.Body = string(data)
if entry.comments != nil && pagerKey != "" {
out.Body = entry.comments.observeResponse(pagerKey, out.Body)
}
} else {
out.Body = base64.StdEncoding.EncodeToString(data)
out.Base64 = true