Feature/Add new doc store upsert and refresh API (#3556)

add new doc store upsert and refresh API
This commit is contained in:
Henry Heng
2024-11-25 15:47:13 +00:00
committed by GitHub
parent 36496b1611
commit a2c36b4447
15 changed files with 1424 additions and 803 deletions
+12 -3
View File
@@ -39,6 +39,7 @@ export const createFileAttachment = async (req: Request) => {
const files = (req.files as Express.Multer.File[]) || []
const fileAttachments = []
if (files.length) {
const isBase64 = req.body.base64
for (const file of files) {
const fileBuffer = fs.readFileSync(file.path)
const fileNames: string[] = []
@@ -70,13 +71,21 @@ export const createFileAttachment = async (req: Request) => {
[fileInputField]: storagePath
}
}
const documents: IDocument[] = await fileLoaderNodeInstance.init(nodeData, '', options)
const pageContents = documents.map((doc) => doc.pageContent).join('\n')
let content = ''
if (isBase64) {
content = fileBuffer.toString('base64')
} else {
const documents: IDocument[] = await fileLoaderNodeInstance.init(nodeData, '', options)
content = documents.map((doc) => doc.pageContent).join('\n')
}
fileAttachments.push({
name: file.originalname,
mimeType: file.mimetype,
size: file.size,
content: pageContents
content
})
} catch (error) {
throw new Error(`Failed operation: createFileAttachment - ${getErrorMessage(error)}`)