File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
arduino-ide-extension/src/browser/create Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -100,14 +100,29 @@ export class CreateApi {
100100 return result ;
101101 }
102102
103- async sketches ( ) : Promise < Create . Sketch [ ] > {
103+ async sketches ( limit = 50 ) : Promise < Create . Sketch [ ] > {
104104 const url = new URL ( `${ this . domain ( ) } /sketches` ) ;
105105 url . searchParams . set ( 'user_id' , 'me' ) ;
106+ url . searchParams . set ( 'limit' , limit . toString ( ) ) ;
106107 const headers = await this . headers ( ) ;
107- const result = await this . run < { sketches : Create . Sketch [ ] } > ( url , {
108- method : 'GET' ,
109- headers,
110- } ) ;
108+ const result : { sketches : Create . Sketch [ ] } = { sketches : [ ] } ;
109+
110+ let partialSketches : Create . Sketch [ ] = [ ] ;
111+ let currentOffset = 0 ;
112+ do {
113+ url . searchParams . set ( 'offset' , currentOffset . toString ( ) ) ;
114+ partialSketches = (
115+ await this . run < { sketches : Create . Sketch [ ] } > ( url , {
116+ method : 'GET' ,
117+ headers,
118+ } )
119+ ) . sketches ;
120+ if ( partialSketches . length != 0 ) {
121+ result . sketches = result . sketches . concat ( partialSketches ) ;
122+ }
123+ currentOffset = currentOffset + limit ;
124+ } while ( partialSketches . length != 0 ) ;
125+
111126 result . sketches . forEach ( ( sketch ) => this . sketchCache . addSketch ( sketch ) ) ;
112127 return result . sketches ;
113128 }
You can’t perform that action at this time.
0 commit comments