From d343a909f5860dd0b710bf49fae889cf597f63a4 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Sat, 12 Oct 2024 14:56:32 +0800 Subject: [PATCH] chore(version): 0.7.16 --- package.json | 2 +- src/main/services/FileManager.ts | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 8fe982d69..0ee297e55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "CherryStudio", - "version": "0.7.15", + "version": "0.7.16", "private": true, "description": "A powerful AI assistant for producer.", "main": "./out/main/index.js", diff --git a/src/main/services/FileManager.ts b/src/main/services/FileManager.ts index 45cc73e73..0e8df8f9b 100644 --- a/src/main/services/FileManager.ts +++ b/src/main/services/FileManager.ts @@ -16,10 +16,12 @@ import { writeFileSync } from 'fs' import { readFile } from 'fs/promises' import officeParser from 'officeparser' import * as path from 'path' +import { chdir } from 'process' import { v4 as uuidv4 } from 'uuid' class FileManager { private storageDir = path.join(app.getPath('userData'), 'Data', 'Files') + private tempDir = path.join(app.getPath('temp'), 'CherryStudio') constructor() { this.initStorageDir() @@ -177,18 +179,27 @@ class FileManager { const filePath = path.join(this.storageDir, id) if (documentExts.includes(path.extname(filePath))) { - return await officeParser.parseOfficeAsync(filePath) + const originalCwd = process.cwd() + try { + chdir(this.tempDir) + const data = await officeParser.parseOfficeAsync(filePath) + chdir(originalCwd) + return data + } catch (error) { + chdir(originalCwd) + logger.error(error) + throw error + } } return fs.readFileSync(filePath, 'utf8') } public createTempFile = async (_: Electron.IpcMainInvokeEvent, fileName: string): Promise => { - const tempDir = path.join(app.getPath('temp'), 'CherryStudio') - if (!fs.existsSync(tempDir)) { - fs.mkdirSync(tempDir, { recursive: true }) + if (!fs.existsSync(this.tempDir)) { + fs.mkdirSync(this.tempDir, { recursive: true }) } - const tempFilePath = path.join(tempDir, `temp_file_${uuidv4()}_${fileName}`) + const tempFilePath = path.join(this.tempDir, `temp_file_${uuidv4()}_${fileName}`) return tempFilePath }