From 9866ee0a4e8713b5461c39b8d2b804681da1ac0b Mon Sep 17 00:00:00 2001 From: alvaro Date: Wed, 23 Jul 2025 11:58:21 +0200 Subject: [PATCH] Add prefix when getting objects from storage --- src/api/yepcodeApi.ts | 6 ++++-- src/storage/yepcodeStorage.ts | 4 ++-- tests/storage/yepcodeStorage.test.ts | 13 +++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/api/yepcodeApi.ts b/src/api/yepcodeApi.ts index f376ae9..8bdf450 100644 --- a/src/api/yepcodeApi.ts +++ b/src/api/yepcodeApi.ts @@ -597,8 +597,10 @@ export class YepCodeApi { return this.request("POST", `/modules/${moduleId}/aliases`, { data }); } - async getObjects(): Promise { - return this.request("GET", "/storage/objects"); + async getObjects( + params: { prefix?: string } = {} + ): Promise { + return this.request("GET", "/storage/objects", { params }); } async getObject(name: string): Promise { diff --git a/src/storage/yepcodeStorage.ts b/src/storage/yepcodeStorage.ts index 4b67e36..ad6a80a 100644 --- a/src/storage/yepcodeStorage.ts +++ b/src/storage/yepcodeStorage.ts @@ -16,8 +16,8 @@ export class YepCodeStorage { return this.api.createObject({ name: filename, file }); } - async list(): Promise { - return this.api.getObjects(); + async list({ prefix }: { prefix?: string } = {}): Promise { + return this.api.getObjects({ prefix }); } async download(filename: string): Promise { diff --git a/tests/storage/yepcodeStorage.test.ts b/tests/storage/yepcodeStorage.test.ts index c2330b5..0bc05dd 100644 --- a/tests/storage/yepcodeStorage.test.ts +++ b/tests/storage/yepcodeStorage.test.ts @@ -45,6 +45,19 @@ describe.skip("YepCodeStorage", () => { const result: StorageObject[] = await storage.list(); expect(Array.isArray(result)).toBe(true); }); + + it("should return a list of storage objects with a prefix", async () => { + const file: File = new File([readFileSync(testFilePath)], testName); + await storage.upload(testName, file); + + const result: StorageObject[] = await storage.list({ + prefix: "test-run", + }); + + expect(Array.isArray(result)).toBe(true); + expect(result.length).toBe(1); + expect(result[0].name).toBe(testName); + }); }); describe("createObject", () => {