diff --git a/arduino-ide-extension/src/browser/create/create-api.ts b/arduino-ide-extension/src/browser/create/create-api.ts index 8c2e4281a..77090071a 100644 --- a/arduino-ide-extension/src/browser/create/create-api.ts +++ b/arduino-ide-extension/src/browser/create/create-api.ts @@ -100,14 +100,29 @@ export class CreateApi { return result; } - async sketches(): Promise { + async sketches(limit = 50): Promise { const url = new URL(`${this.domain()}/sketches`); url.searchParams.set('user_id', 'me'); + url.searchParams.set('limit', limit.toString()); const headers = await this.headers(); - const result = await this.run<{ sketches: Create.Sketch[] }>(url, { - method: 'GET', - headers, - }); + const result: { sketches: Create.Sketch[] } = { sketches: [] }; + + let partialSketches: Create.Sketch[] = []; + let currentOffset = 0; + do { + url.searchParams.set('offset', currentOffset.toString()); + partialSketches = ( + await this.run<{ sketches: Create.Sketch[] }>(url, { + method: 'GET', + headers, + }) + ).sketches; + if (partialSketches.length != 0) { + result.sketches = result.sketches.concat(partialSketches); + } + currentOffset = currentOffset + limit; + } while (partialSketches.length != 0); + result.sketches.forEach((sketch) => this.sketchCache.addSketch(sketch)); return result.sketches; }