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 {
4949 ...query ,
5050 start_cursor : next_cursor || undefined ,
5151 } )
52- ) ;
52+ ) ;
5353
5454 results . push ( ...response . results ) ;
55-
55+
5656 next_cursor = response . next_cursor ;
5757 } while ( next_cursor ) ;
5858
@@ -66,20 +66,25 @@ export class NotionApiFacade {
6666 }
6767
6868 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+ } )
7980 ) ;
80- }
8181
82- return result ;
82+ results . push ( ...response . results ) ;
83+
84+ next_cursor = response . next_cursor ;
85+ } while ( next_cursor ) ;
86+
87+ return results ;
8388 }
8489
8590 printStats ( ) {
Original file line number Diff line number Diff line change @@ -20,8 +20,7 @@ export class RecursiveBodyRenderer {
2020
2121 const childs = await this . publicApi . listBlockChildren ( page . id ) ;
2222
23- // todo: paging
24- const renderChilds = childs . results . map (
23+ const renderChilds = childs . map (
2524 async ( x ) => await this . renderBlock ( x , "" , context )
2625 ) ;
2726 const blocks = await Promise . all ( renderChilds ) ;
@@ -47,7 +46,7 @@ export class RecursiveBodyRenderer {
4746 // blocks, see https://developers.notion.com/reference/retrieve-a-block
4847 // "If a block contains the key has_children: true, use the Retrieve block children endpoint to get the list of children"
4948 const children = block . has_children
50- ? ( await this . publicApi . listBlockChildren ( block . id ) ) . results
49+ ? ( await this . publicApi . listBlockChildren ( block . id ) )
5150 : [ ] ;
5251
5352 const childIndent = indent + " " . repeat ( parentBlock ?. childIndent || 0 ) ;
You can’t perform that action at this time.
0 commit comments