We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 04eb997 commit a69d1faCopy full SHA for a69d1fa
1 file changed
src/api.ts
@@ -1,14 +1,16 @@
1
import { CommentDetailsResponse, CommentSort, CommentType } from './types/api'
2
import { Reply } from './types/reply'
3
4
+// for performance and rate limit, we only fetch the first 20 pages
5
+const PAGE_LIMIT = 20
6
const replies: Reply[] = []
7
8
export async function fetchComments(videoId: string) {
- if (replies.length > 0) {
9
+ if (replies.length > 0) {
10
return replies
11
}
12
- const pageSize = 40
13
+ const pageSize = 49
14
let page = 1
15
16
while (true) {
@@ -36,7 +38,10 @@ export async function fetchComments(videoId: string) {
36
38
37
39
replies.push(...(data.data.replies ?? []))
40
- if (page * pageSize >= data.data.page.count) {
41
+ if (
42
+ page * pageSize >=
43
+ Math.min(PAGE_LIMIT * pageSize, data.data.page.count)
44
+ ) {
45
break
46
47
0 commit comments