Skip to content

Commit

Permalink
fix: add pptx encoding try catch (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk authored May 8, 2024
1 parent 2e468fc commit 7b75a99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/service/common/buffer/rawText/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ try {
console.log(error);
}

export const MongoRwaTextBuffer: Model<RawTextBufferSchemaType> =
export const MongoRawTextBuffer: Model<RawTextBufferSchemaType> =
models[collectionName] || model(collectionName, RawTextBufferSchema);
MongoRwaTextBuffer.syncIndexes();
MongoRawTextBuffer.syncIndexes();
6 changes: 3 additions & 3 deletions packages/service/common/file/gridfs/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -208,7 +208,7 @@ export const readFileContentFromMongo = async ({
});

if (rawText.trim()) {
MongoRwaTextBuffer.create({
MongoRawTextBuffer.create({
sourceId: fileId,
rawText,
metadata: {
Expand Down
22 changes: 16 additions & 6 deletions packages/service/worker/file/parseOffice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7b75a99

Please sign in to comment.