chore(version): 0.7.16
This commit is contained in:
parent
de5db4f805
commit
5b357f14e5
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "CherryStudio",
|
"name": "CherryStudio",
|
||||||
"version": "0.7.15",
|
"version": "0.7.16",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "A powerful AI assistant for producer.",
|
"description": "A powerful AI assistant for producer.",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
|
|||||||
@ -16,10 +16,12 @@ import { writeFileSync } from 'fs'
|
|||||||
import { readFile } from 'fs/promises'
|
import { readFile } from 'fs/promises'
|
||||||
import officeParser from 'officeparser'
|
import officeParser from 'officeparser'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
import { chdir } from 'process'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
|
||||||
class FileManager {
|
class FileManager {
|
||||||
private storageDir = path.join(app.getPath('userData'), 'Data', 'Files')
|
private storageDir = path.join(app.getPath('userData'), 'Data', 'Files')
|
||||||
|
private tempDir = path.join(app.getPath('temp'), 'CherryStudio')
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.initStorageDir()
|
this.initStorageDir()
|
||||||
@ -29,6 +31,9 @@ class FileManager {
|
|||||||
if (!fs.existsSync(this.storageDir)) {
|
if (!fs.existsSync(this.storageDir)) {
|
||||||
fs.mkdirSync(this.storageDir, { recursive: true })
|
fs.mkdirSync(this.storageDir, { recursive: true })
|
||||||
}
|
}
|
||||||
|
if (!fs.existsSync(this.tempDir)) {
|
||||||
|
fs.mkdirSync(this.tempDir, { recursive: true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFileHash = async (filePath: string): Promise<string> => {
|
private getFileHash = async (filePath: string): Promise<string> => {
|
||||||
@ -177,18 +182,27 @@ class FileManager {
|
|||||||
const filePath = path.join(this.storageDir, id)
|
const filePath = path.join(this.storageDir, id)
|
||||||
|
|
||||||
if (documentExts.includes(path.extname(filePath))) {
|
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')
|
return fs.readFileSync(filePath, 'utf8')
|
||||||
}
|
}
|
||||||
|
|
||||||
public createTempFile = async (_: Electron.IpcMainInvokeEvent, fileName: string): Promise<string> => {
|
public createTempFile = async (_: Electron.IpcMainInvokeEvent, fileName: string): Promise<string> => {
|
||||||
const tempDir = path.join(app.getPath('temp'), 'CherryStudio')
|
if (!fs.existsSync(this.tempDir)) {
|
||||||
if (!fs.existsSync(tempDir)) {
|
fs.mkdirSync(this.tempDir, { recursive: true })
|
||||||
fs.mkdirSync(tempDir, { recursive: true })
|
|
||||||
}
|
}
|
||||||
const tempFilePath = path.join(tempDir, `temp_file_${uuidv4()}_${fileName}`)
|
const tempFilePath = path.join(this.tempDir, `temp_file_${uuidv4()}_${fileName}`)
|
||||||
return tempFilePath
|
return tempFilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user