@@ -370,63 +370,58 @@ class IndexifyClient {
370
370
}
371
371
372
372
async uploadFile (
373
- extractionGraphNames : string | string [ ] ,
373
+ extractionGraphNames : string ,
374
374
fileInput : string | Blob ,
375
375
labels : Record < string , any > = { } ,
376
376
newContentId ?: string
377
377
) : Promise < string > {
378
378
const isNodeEnv = typeof window === "undefined" ;
379
- const extractionGraphNamesArray = Array . isArray ( extractionGraphNames ) ? extractionGraphNames : [ extractionGraphNames ] ;
379
+ let formData : any ;
380
380
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" ) ;
400
393
}
394
+ formData = new FormData ( ) ;
395
+ formData . append ( "labels" , JSON . stringify ( labels ) ) ;
396
+ formData . append ( "file" , fileInput ) ;
397
+ }
401
398
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" : "*/*"
412
408
}
413
- ) ;
409
+ }
410
+ ) ;
414
411
415
- const contentId = response . data . content_id ;
412
+ const contentId = response . data . content_id ;
416
413
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 "" ;
425
420
}
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
426
424
}
427
-
428
- console . error ( `Failed to retrieve content ID for all extraction graphs: ${ extractionGraphNamesArray . join ( ", " ) } ` ) ;
429
- return "" ;
430
425
}
431
426
432
427
async getExtractionGraphs ( ) : Promise < ExtractionGraph [ ] > {
0 commit comments