Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { isS3FileKey } = require('./S3Directory')

describe('S3Directory', () => {
describe('isS3FileKey', () => {
it('skips S3 directory marker keys', () => {
expect(isS3FileKey('docs/')).toBe(false)
expect(isS3FileKey('docs/nested/')).toBe(false)
})

it('keeps regular file keys, including empty file keys with extensions', () => {
expect(isS3FileKey('docs/readme.txt')).toBe(true)
expect(isS3FileKey('empty-file.txt')).toBe(true)
})

it('skips missing keys', () => {
expect(isS3FileKey()).toBe(false)
expect(isS3FileKey('')).toBe(false)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { TextSplitter } from '@langchain/textsplitters'
import { CSVLoader } from '../Csv/CsvLoader'
import { LoadOfSheet } from '../MicrosoftExcel/ExcelLoader'
import { PowerpointLoader } from '../MicrosoftPowerpoint/PowerpointLoader'

const isS3FileKey = (key?: string): key is string => Boolean(key && !key.endsWith('/'))

class S3_DocumentLoaders implements INode {
label: string
name: string
Expand Down Expand Up @@ -184,7 +187,7 @@ class S3_DocumentLoaders implements INode {
})
)

const keys: string[] = (listObjectsOutput?.Contents ?? []).filter((item) => item.Key && item.ETag).map((item) => item.Key!)
const keys: string[] = (listObjectsOutput?.Contents ?? []).filter((item) => isS3FileKey(item.Key) && item.ETag).map((item) => item.Key!)

await Promise.all(
keys.map(async (key) => {
Expand Down Expand Up @@ -290,4 +293,4 @@ class S3_DocumentLoaders implements INode {
}
}
}
module.exports = { nodeClass: S3_DocumentLoaders }
module.exports = { nodeClass: S3_DocumentLoaders, isS3FileKey }