| 360 | } |
| 361 | |
| 362 | class MultiFileLoader extends BaseDocumentLoader { |
| 363 | constructor(public fileBlobs: { blob: Blob; ext: string }[], public loaders: LoadersMapping) { |
| 364 | super() |
| 365 | |
| 366 | if (Object.keys(loaders).length === 0) { |
| 367 | throw new Error('Must provide at least one loader') |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | public async load(): Promise<Document[]> { |
| 372 | const documents: Document[] = [] |
| 373 | |
| 374 | for (const fileBlob of this.fileBlobs) { |
| 375 | const loaderFactory = this.loaders[fileBlob.ext] |
| 376 | if (loaderFactory) { |
| 377 | const loader = loaderFactory(fileBlob.blob) |
| 378 | documents.push(...(await loader.load())) |
| 379 | } else { |
| 380 | const loader = new TextLoader(fileBlob.blob) |
| 381 | try { |
| 382 | documents.push(...(await loader.load())) |
| 383 | } catch (error) { |
| 384 | throw new Error(`Error loading file`) |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | return documents |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | module.exports = { nodeClass: File_DocumentLoaders } |
nothing calls this directly
no outgoing calls
no test coverage detected