Skip to content

Commit

Permalink
Fix upload file labels (#37)
Browse files Browse the repository at this point in the history
* fix upload file labels

* version bump
  • Loading branch information
lucasjacks0n authored Jun 17, 2024
1 parent f3a6612 commit 477eb08
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 4 additions & 16 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class IndexifyClient {
fileInput: string | Blob,
labels: Record<string, any> = {},
id?: string
): Promise<string> {
): Promise<string> {
function isBlob(input: any): input is Blob {
return input instanceof Blob;
}
Expand All @@ -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;
Expand All @@ -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, {
Expand Down
8 changes: 4 additions & 4 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -250,7 +250,7 @@ test("downloadContent", async () => {
]);

const content = await client.getExtractedContent({
labels_eq: "source:testdownload",
labelsEq: "source:testdownload",
});
expect(content.length).toBeGreaterThanOrEqual(1);

Expand Down

0 comments on commit 477eb08

Please sign in to comment.