WeKnora/internal/datasource/connector/feishu/drive
linus-liu-web a282d1091e
fix(feishu): 云盘分页补上 #3645 给 wiki 加的重复 page token 防护 (#3770)
ListDriveFilesAllPages 只以 next_page_token 是否为空作为终止条件,既不看
has_more,也没有重复 token 检测;同一文件里同一厂商的 ListWikiSpaces /
ListWikiNodes 已在 #3645 修过,云盘这两条防护都漏了。

厂商返回 has_more=false 但残留非空 token,或返回重复的 page_token 时,循环会
拿同一个 token 反复请求同一页:定时同步任务会在 asynq 的 2h 超时前一直打 API
(scheduler 侧 MaxRetry 5),资源选择器
GET /api/v1/datasources/:id/resources 永不返回,同时 all 每轮 append 不断增长。

按 #3645 的既有写法原样修复:listDriveFiles 透出 has_more,循环改为
if !hasMore || next == "" 才退出,并用 seenPageTokens 记录已用过的 token,重复即
返回 "feishu drive file pagination repeated page token" 错误。正常多页语义不变
(仍返回完整列表),只是不再空转。

测试:TestClientDriveListFilesPagination(drive 包)用 httptest 覆盖重复 token、
has_more=false 带残留 token、正常两页三种情况;注释掉守卫后该用例在 2s 内发出
4 万+ 次请求并以 context deadline exceeded 失败。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-09-29 00:51:19 +08:00
..
connector.go feat(datasource): persist source created time; Feishu uses content edit time for source_updated_at (#3083) 2026-09-07 19:39:01 +08:00
cursor_test.go feat(feishu-driver): 新增飞书云盘数据源 (#2466) 2026-08-05 19:39:49 +08:00
drive_blocks_test.go feat(feishu-driver): 新增飞书云盘数据源 (#2466) 2026-08-05 19:39:49 +08:00
helpers_test.go feat(feishu-driver): 新增飞书云盘数据源 (#2466) 2026-08-05 19:39:49 +08:00
pagination_test.go fix(feishu): 云盘分页补上 #3645 给 wiki 加的重复 page token 防护 (#3770) 2026-09-29 00:51:19 +08:00