Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

Commit 5d483c1

Browse files
Merge pull request #50 from tensorlakeai/feat/fix-upload
feat: updated upload endpoint
2 parents c6b266a + f1b338e commit 5d483c1

File tree

3 files changed

+42
-47
lines changed

3 files changed

+42
-47
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "getindexify",
3-
"version": "0.0.68",
3+
"version": "0.0.70",
44
"description": "This is the TypeScript client for interacting with the Indexify service.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/client.ts

+39-44
Original file line numberDiff line numberDiff line change
@@ -370,63 +370,58 @@ class IndexifyClient {
370370
}
371371

372372
async uploadFile(
373-
extractionGraphNames: string | string[],
373+
extractionGraphNames: string,
374374
fileInput: string | Blob,
375375
labels: Record<string, any> = {},
376376
newContentId?: string
377377
): Promise<string> {
378378
const isNodeEnv = typeof window === "undefined";
379-
const extractionGraphNamesArray = Array.isArray(extractionGraphNames) ? extractionGraphNames : [extractionGraphNames];
379+
let formData: any;
380380

381-
for (const extractionGraph of extractionGraphNamesArray) {
382-
let formData: any;
383-
384-
if (isNodeEnv) {
385-
if (typeof fileInput !== "string") {
386-
throw Error("Expected string for file path in Node environment");
387-
}
388-
const fs = require("fs");
389-
const FormData = require("form-data");
390-
formData = new FormData();
391-
formData.append("labels", JSON.stringify(labels));
392-
formData.append("file", fs.createReadStream(fileInput));
393-
} else {
394-
if (!(fileInput instanceof Blob)) {
395-
throw Error("Expected Blob in browser environment");
396-
}
397-
formData = new FormData();
398-
formData.append("labels", JSON.stringify(labels));
399-
formData.append("file", fileInput);
381+
if (isNodeEnv) {
382+
if (typeof fileInput !== "string") {
383+
throw Error("Expected string for file path in Node environment");
384+
}
385+
const fs = require("fs");
386+
const FormData = require("form-data");
387+
formData = new FormData();
388+
formData.append("labels", JSON.stringify(labels));
389+
formData.append("file", fs.createReadStream(fileInput));
390+
} else {
391+
if (!(fileInput instanceof Blob)) {
392+
throw Error("Expected Blob in browser environment");
400393
}
394+
formData = new FormData();
395+
formData.append("labels", JSON.stringify(labels));
396+
formData.append("file", fileInput);
397+
}
401398

402-
try {
403-
const response = await this.client.post(
404-
`/namespaces/default/extraction_graphs/${extractionGraph}/extract`,
405-
formData,
406-
{
407-
params: newContentId ? { id: newContentId } : undefined,
408-
headers: {
409-
"Content-Type": "multipart/form-data",
410-
"accept": "*/*"
411-
}
399+
try {
400+
const response = await this.client.post(
401+
`/extraction_graphs/${extractionGraphNames}/extract`,
402+
formData,
403+
{
404+
params: newContentId ? { id: newContentId } : undefined,
405+
headers: {
406+
"Content-Type": "multipart/form-data",
407+
"accept": "*/*"
412408
}
413-
);
409+
}
410+
);
414411

415-
const contentId = response.data.content_id;
412+
const contentId = response.data.content_id;
416413

417-
if (contentId) {
418-
console.log(`Content ID retrieved: ${contentId}`);
419-
return contentId;
420-
} else {
421-
console.warn(`Unexpected: No content ID found in response for extraction graph: ${extractionGraph}`);
422-
}
423-
} catch (error) {
424-
console.error(`Error during extraction for graph ${extractionGraph}:`, error);
414+
if (contentId) {
415+
console.log(`Content ID retrieved: ${contentId}`);
416+
return contentId;
417+
} else {
418+
console.warn(`Unexpected: No content ID found in response for extraction graph: ${extractionGraphNames}`);
419+
return "";
425420
}
421+
} catch (error) {
422+
console.error(`Error during extraction for graph ${extractionGraphNames}:`, error);
423+
throw error; // Re-throw the error to be handled by the caller
426424
}
427-
428-
console.error(`Failed to retrieve content ID for all extraction graphs: ${extractionGraphNamesArray.join(", ")}`);
429-
return "";
430425
}
431426

432427
async getExtractionGraphs(): Promise<ExtractionGraph[]> {

0 commit comments

Comments
 (0)