|
1 | 1 | import { DirSource, FileMetadata, FileSource, SourcePart } from './types.js' |
2 | 2 | import { getFileName } from './utils.js' |
3 | 3 |
|
4 | | -function s3listv2(bucket: string, prefix: string) { |
| 4 | +function s3list(bucket: string, prefix: string) { |
5 | 5 | const url = `https://${bucket}.s3.amazonaws.com/?list-type=2&prefix=${prefix}&delimiter=/` |
6 | 6 | return fetch(url) |
7 | 7 | .then(res => { |
@@ -58,7 +58,6 @@ function getSourceParts(sourceId: string): SourcePart[] { |
58 | 58 | ? [`${protocol}://${rest.split('/', 1)[0]}`, ...rest.split('/').slice(1)] |
59 | 59 | : sourceId.split('/') |
60 | 60 | const sourceParts = [ |
61 | | - //{ 'text': '/', 'sourceId': '' }, |
62 | 61 | ...parts.map((part, depth) => { |
63 | 62 | const slashSuffix = depth === parts.length - 1 ? '' : '/' |
64 | 63 | return { |
@@ -94,13 +93,17 @@ export function getHttpSource(sourceId: string, options?: {requestInit?: Request |
94 | 93 | sourceId, |
95 | 94 | sourceParts, |
96 | 95 | prefix, |
97 | | - listFiles: () => s3listv2(bucket, prefix).then(items => |
| 96 | + listFiles: () => s3list(bucket, prefix).then(items => |
98 | 97 | items |
99 | 98 | .filter(item => item.key !== undefined) |
100 | 99 | .map(item => { |
101 | | - const isDirectory = item.key!.endsWith('/') |
| 100 | + if (!item.key) { |
| 101 | + throw new Error('Key is undefined') |
| 102 | + } |
| 103 | + const isDirectory = item.key.endsWith('/') |
102 | 104 | const itemSourceId = `https://${bucket}.s3.amazonaws.com/${item.key}` |
103 | | - let name = item.key!.split('/').pop() || item.key |
| 105 | + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing |
| 106 | + let name = item.key.split('/').pop() || item.key |
104 | 107 | if (name && isDirectory) { |
105 | 108 | name = name.replace(prefix, '') |
106 | 109 | } |
|
0 commit comments