Skip to content

Commit

Permalink
chore(version): 0.7.16
Browse files Browse the repository at this point in the history
  • Loading branch information
kangfenmao committed Oct 12, 2024
1 parent de5db4f commit d343a90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 16 additions & 5 deletions src/main/services/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<string> => {
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
}

Expand Down

0 comments on commit d343a90

Please sign in to comment.