diff --git a/packages/service/common/buffer/rawText/schema.ts b/packages/service/common/buffer/rawText/schema.ts index b0735e5c6..d86d486ad 100644 --- a/packages/service/common/buffer/rawText/schema.ts +++ b/packages/service/common/buffer/rawText/schema.ts @@ -28,6 +28,6 @@ try { console.log(error); } -export const MongoRwaTextBuffer: Model = +export const MongoRawTextBuffer: Model = models[collectionName] || model(collectionName, RawTextBufferSchema); -MongoRwaTextBuffer.syncIndexes(); +MongoRawTextBuffer.syncIndexes(); diff --git a/packages/service/common/file/gridfs/controller.ts b/packages/service/common/file/gridfs/controller.ts index 34e9658d4..daeda115e 100644 --- a/packages/service/common/file/gridfs/controller.ts +++ b/packages/service/common/file/gridfs/controller.ts @@ -6,7 +6,7 @@ import { DatasetFileSchema } from '@fastgpt/global/core/dataset/type'; import { MongoFileSchema } from './schema'; import { detectFileEncoding } from '@fastgpt/global/common/file/tools'; import { CommonErrEnum } from '@fastgpt/global/common/error/code/common'; -import { MongoRwaTextBuffer } from '../../buffer/rawText/schema'; +import { MongoRawTextBuffer } from '../../buffer/rawText/schema'; import { readFileRawContent } from '../read/utils'; import { PassThrough } from 'stream'; @@ -162,7 +162,7 @@ export const readFileContentFromMongo = async ({ filename: string; }> => { // read buffer - const fileBuffer = await MongoRwaTextBuffer.findOne({ sourceId: fileId }).lean(); + const fileBuffer = await MongoRawTextBuffer.findOne({ sourceId: fileId }).lean(); if (fileBuffer) { return { rawText: fileBuffer.rawText, @@ -208,7 +208,7 @@ export const readFileContentFromMongo = async ({ }); if (rawText.trim()) { - MongoRwaTextBuffer.create({ + MongoRawTextBuffer.create({ sourceId: fileId, rawText, metadata: { diff --git a/packages/service/worker/file/parseOffice.ts b/packages/service/worker/file/parseOffice.ts index 4777483cf..05dabf9ec 100644 --- a/packages/service/worker/file/parseOffice.ts +++ b/packages/service/worker/file/parseOffice.ts @@ -44,9 +44,13 @@ const parsePowerPoint = async ({ } // Returning an array of all the xml contents read using fs.readFileSync - const xmlContentArray = files.map((file) => - fs.readFileSync(`${decompressPath}/${file.path}`, encoding) - ); + const xmlContentArray = files.map((file) => { + try { + return fs.readFileSync(`${decompressPath}/${file.path}`, encoding); + } catch (err) { + return fs.readFileSync(`${decompressPath}/${file.path}`, 'utf-8'); + } + }); let responseArr: string[] = []; @@ -95,9 +99,15 @@ export const parseOffice = async ({ // const decompressPath = `${DEFAULTDECOMPRESSSUBLOCATION}/test`; // write new file - fs.writeFileSync(filepath, buffer, { - encoding - }); + try { + fs.writeFileSync(filepath, buffer, { + encoding + }); + } catch (err) { + fs.writeFileSync(filepath, buffer, { + encoding: 'utf-8' + }); + } const text = await (async () => { try {