chore: remove useless code

This commit is contained in:
kangfenmao 2025-03-28 09:19:04 +08:00
parent 29b5ba787b
commit 7263a682b7
4 changed files with 2 additions and 68 deletions

View File

@ -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')
}
}

View File

@ -213,11 +213,6 @@ class FileStorage {
public readFile = async (_: Electron.IpcMainInvokeEvent, id: string): Promise<string> => {
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()

View File

@ -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 || [])]

View File

@ -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
}
}