fix dataset fetch for index.md generation

This commit is contained in:
Cat /dev/Nulo 2025-01-27 10:15:53 -03:00
parent 3047d9f596
commit 74735260bb

View file

@ -36,18 +36,28 @@ function getS3Client() {
}, },
}); });
} }
export async function listDirectory(directoryName: string) { export async function listDirectory(directoryName: string) {
const { B2_BUCKET_NAME } = getVariables(); const { B2_BUCKET_NAME } = getVariables();
const s3 = getS3Client(); const s3 = getS3Client();
let allContents: string[] = [];
let continuationToken: string | undefined;
do {
const command = new ListObjectsV2Command({ const command = new ListObjectsV2Command({
Bucket: B2_BUCKET_NAME, Bucket: B2_BUCKET_NAME,
Prefix: directoryName ? `${directoryName}/` : "", Prefix: directoryName ? `${directoryName}/` : "",
Delimiter: "/", Delimiter: "/",
ContinuationToken: continuationToken,
}); });
const response = await s3.send(command); const response = await s3.send(command);
return response.Contents?.map((item) => item.Key ?? "") ?? []; allContents = allContents.concat(
response.Contents?.map((item) => item.Key ?? "") ?? []
);
continuationToken = response.NextContinuationToken;
} while (continuationToken);
return allContents;
} }
export async function getFileContent(fileName: string) { export async function getFileContent(fileName: string) {