diff --git a/package.json b/package.json index 6525065..400a7da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "getindexify", - "version": "0.0.45", + "version": "0.0.46", "description": "This is the TypeScript client for interacting with the Indexify service.", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/src/client.ts b/src/client.ts index d9a392b..d077cd4 100644 --- a/src/client.ts +++ b/src/client.ts @@ -358,7 +358,7 @@ class IndexifyClient { fileInput: string | Blob, labels: Record = {}, id?: string - ): Promise { + ): Promise { function isBlob(input: any): input is Blob { return input instanceof Blob; } @@ -383,18 +383,11 @@ class IndexifyClient { // Create form const FormData = require("form-data"); const formData = new FormData(); + formData.append("labels", JSON.stringify(labels)); formData.append("file", fs.createReadStream(fileInput as string)); //stream - // Append labels to the form data - Object.keys(labels).forEach((key) => { - formData.append(key, labels[key]); - }); - // Upload File const res = await this.client.post("upload_file", formData, { - headers: { - ...formData.getHeaders(), - }, params, }); return res.data.content_id; @@ -403,15 +396,10 @@ class IndexifyClient { if (!isBlob(fileInput)) { throw Error("Expected blob"); } - // Create form const formData = new FormData(); - formData.append("file", fileInput); //blob - - // Append labels to the form data - Object.keys(labels).forEach((key) => { - formData.append(key, labels[key]); - }); + formData.append("labels", JSON.stringify(labels)); + formData.append("file", fileInput); // Upload File const res = await this.client.post("/upload_file", formData, { diff --git a/tests/client.test.ts b/tests/client.test.ts index 5c1d0a6..b059d1b 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -174,14 +174,14 @@ test("getExtractedContent", async () => { let content; - content = await client.getExtractedContent({ parent_id: "idontexist" }); + content = await client.getExtractedContent({ parentId: "idontexist" }); expect(content.length).toBe(0); - content = await client.getExtractedContent({ labels_eq: "source:test" }); + content = await client.getExtractedContent({ labelsEq: "source:test" }); expect(content.length).toBe(2); expect(content[0].content_url).toContain("http://"); - content = await client.getExtractedContent({ labels_eq: "source:nothing" }); + content = await client.getExtractedContent({ labelsEq: "source:nothing" }); expect(content.length).toBe(0); }); @@ -250,7 +250,7 @@ test("downloadContent", async () => { ]); const content = await client.getExtractedContent({ - labels_eq: "source:testdownload", + labelsEq: "source:testdownload", }); expect(content.length).toBeGreaterThanOrEqual(1);