From 5e4d640ed7b1d61b82e65004bc18af593f96f8ba Mon Sep 17 00:00:00 2001 From: Jared McQueen Date: Tue, 11 Jun 2024 17:05:04 -0400 Subject: [PATCH] fix totalChars accumulator for undefined pageContent (#2619) --- packages/server/src/services/documentstore/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/server/src/services/documentstore/index.ts b/packages/server/src/services/documentstore/index.ts index 3492602fa11..ff758642086 100644 --- a/packages/server/src/services/documentstore/index.ts +++ b/packages/server/src/services/documentstore/index.ts @@ -600,7 +600,12 @@ const _saveChunksToStorage = async (data: IDocumentStoreLoaderForPreview, entity await appServer.AppDataSource.getRepository(DocumentStoreFileChunk).delete({ docId: newLoaderId }) if (response.chunks) { //step 8: now save the new chunks - const totalChars = response.chunks.reduce((acc: number, chunk) => acc + chunk.pageContent.length, 0) + const totalChars = response.chunks.reduce((acc, chunk) => { + if (chunk.pageContent) { + return acc + chunk.pageContent.length + } + return acc + }, 0) response.chunks.map(async (chunk: IDocument, index: number) => { const docChunk: DocumentStoreFileChunk = { docId: newLoaderId,