File tree Expand file tree Collapse file tree 2 files changed +21
-17
lines changed Expand file tree Collapse file tree 2 files changed +21
-17
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,10 @@ export class NotionApiFacade {
49
49
...query ,
50
50
start_cursor : next_cursor || undefined ,
51
51
} )
52
- ) ;
52
+ ) ;
53
53
54
54
results . push ( ...response . results ) ;
55
-
55
+
56
56
next_cursor = response . next_cursor ;
57
57
} while ( next_cursor ) ;
58
58
@@ -66,20 +66,25 @@ export class NotionApiFacade {
66
66
}
67
67
68
68
async listBlockChildren ( blockId : string ) {
69
- const result = await this . withRetry (
70
- async ( ) =>
71
- await this . client . blocks . children . list ( {
72
- block_id : blockId ,
73
- } )
74
- ) ; // todo: paging here?
75
-
76
- if ( result . next_cursor ) {
77
- throw new Error (
78
- `Paging not implemented, block ${ blockId } has more children than returned in a single request`
69
+ const results = [ ] ;
70
+
71
+ let next_cursor : string | null = null ;
72
+
73
+ do {
74
+ const response = await this . withRetry (
75
+ async ( ) =>
76
+ await this . client . blocks . children . list ( {
77
+ block_id : blockId ,
78
+ start_cursor : next_cursor || undefined ,
79
+ } )
79
80
) ;
80
- }
81
81
82
- return result ;
82
+ results . push ( ...response . results ) ;
83
+
84
+ next_cursor = response . next_cursor ;
85
+ } while ( next_cursor ) ;
86
+
87
+ return results ;
83
88
}
84
89
85
90
printStats ( ) {
Original file line number Diff line number Diff line change @@ -20,8 +20,7 @@ export class RecursiveBodyRenderer {
20
20
21
21
const childs = await this . publicApi . listBlockChildren ( page . id ) ;
22
22
23
- // todo: paging
24
- const renderChilds = childs . results . map (
23
+ const renderChilds = childs . map (
25
24
async ( x ) => await this . renderBlock ( x , "" , context )
26
25
) ;
27
26
const blocks = await Promise . all ( renderChilds ) ;
@@ -47,7 +46,7 @@ export class RecursiveBodyRenderer {
47
46
// blocks, see https://developers.notion.com/reference/retrieve-a-block
48
47
// "If a block contains the key has_children: true, use the Retrieve block children endpoint to get the list of children"
49
48
const children = block . has_children
50
- ? ( await this . publicApi . listBlockChildren ( block . id ) ) . results
49
+ ? ( await this . publicApi . listBlockChildren ( block . id ) )
51
50
: [ ] ;
52
51
53
52
const childIndent = indent + " " . repeat ( parentBlock ?. childIndent || 0 ) ;
You can’t perform that action at this time.
0 commit comments