From 7263a682b745301a7adff7e3bf90c36db81804a4 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Fri, 28 Mar 2025 09:19:04 +0800 Subject: [PATCH] chore: remove useless code --- src/main/services/FileService.ts | 4 --- src/main/services/FileStorage.ts | 5 --- src/main/services/MCPService.ts | 3 +- src/utils/file.ts | 58 -------------------------------- 4 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 src/utils/file.ts diff --git a/src/main/services/FileService.ts b/src/main/services/FileService.ts index 82034d1c..39255e15 100644 --- a/src/main/services/FileService.ts +++ b/src/main/services/FileService.ts @@ -2,10 +2,6 @@ import fs from 'node:fs' export default class FileService { public static async readFile(_: Electron.IpcMainInvokeEvent, path: string) { - const stats = fs.statSync(path) - if (stats.isDirectory()) { - throw new Error(`Cannot read directory: ${path}`) - } return fs.readFileSync(path, 'utf8') } } diff --git a/src/main/services/FileStorage.ts b/src/main/services/FileStorage.ts index e6c4bd91..9557e17c 100644 --- a/src/main/services/FileStorage.ts +++ b/src/main/services/FileStorage.ts @@ -213,11 +213,6 @@ class FileStorage { public readFile = async (_: Electron.IpcMainInvokeEvent, id: string): Promise => { const filePath = path.join(this.storageDir, id) - const stats = await fs.promises.stat(filePath) - - if (stats.isDirectory()) { - throw new Error(`Cannot read directory: ${filePath}`) - } if (documentExts.includes(path.extname(filePath))) { const originalCwd = process.cwd() diff --git a/src/main/services/MCPService.ts b/src/main/services/MCPService.ts index 670136e5..0b33269d 100644 --- a/src/main/services/MCPService.ts +++ b/src/main/services/MCPService.ts @@ -3,6 +3,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js' import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js' import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js' import { MCPServer } from '@types' +import { app } from 'electron' import Logger from 'electron-log' class McpService { @@ -43,7 +44,7 @@ class McpService { } // Create new client instance for each connection - this.client = new Client({ name: 'McpService', version: '1.0.0' }, { capabilities: {} }) + this.client = new Client({ name: 'Cherry Studio', version: app.getVersion() }, { capabilities: {} }) const args = [...(server.args || [])] diff --git a/src/utils/file.ts b/src/utils/file.ts deleted file mode 100644 index 38a6e89e..00000000 --- a/src/utils/file.ts +++ /dev/null @@ -1,58 +0,0 @@ -import fs from 'fs' -import os from 'os' -import path from 'path' - -/** - * 获取用户下载目录路径 - */ -export function getDownloadsPath(): string { - return path.join(os.homedir(), 'Downloads') -} - -/** - * 读取下载目录中的文件 - * @param filename 文件名 - * @returns 文件内容 - */ -export function readFileFromDownloads(filename: string): string { - const downloadsPath = getDownloadsPath() - const filePath = path.join(downloadsPath, filename) - - try { - // 检查文件是否存在 - if (!fs.existsSync(filePath)) { - throw new Error(`File not found: ${filename}`) - } - - // 检查是否是文件而不是目录 - const stats = fs.statSync(filePath) - if (stats.isDirectory()) { - throw new Error(`${filename} is a directory, not a file`) - } - - // 读取文件内容 - return fs.readFileSync(filePath, 'utf-8') - } catch (error) { - if (error instanceof Error) { - throw new Error(`Error reading file: ${error.message}`) - } - throw error - } -} - -/** - * 列出下载目录中的所有文件 - * @returns 文件名列表 - */ -export function listDownloadsFiles(): string[] { - const downloadsPath = getDownloadsPath() - - try { - return fs.readdirSync(downloadsPath) - } catch (error) { - if (error instanceof Error) { - throw new Error(`Error listing downloads directory: ${error.message}`) - } - throw error - } -}