chore: remove useless code
This commit is contained in:
parent
29b5ba787b
commit
7263a682b7
@ -2,10 +2,6 @@ import fs from 'node:fs'
|
|||||||
|
|
||||||
export default class FileService {
|
export default class FileService {
|
||||||
public static async readFile(_: Electron.IpcMainInvokeEvent, path: string) {
|
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')
|
return fs.readFileSync(path, 'utf8')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -213,11 +213,6 @@ class FileStorage {
|
|||||||
|
|
||||||
public readFile = async (_: Electron.IpcMainInvokeEvent, id: string): Promise<string> => {
|
public readFile = async (_: Electron.IpcMainInvokeEvent, id: string): Promise<string> => {
|
||||||
const filePath = path.join(this.storageDir, id)
|
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))) {
|
if (documentExts.includes(path.extname(filePath))) {
|
||||||
const originalCwd = process.cwd()
|
const originalCwd = process.cwd()
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
|||||||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
||||||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
||||||
import { MCPServer } from '@types'
|
import { MCPServer } from '@types'
|
||||||
|
import { app } from 'electron'
|
||||||
import Logger from 'electron-log'
|
import Logger from 'electron-log'
|
||||||
|
|
||||||
class McpService {
|
class McpService {
|
||||||
@ -43,7 +44,7 @@ class McpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create new client instance for each connection
|
// 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 || [])]
|
const args = [...(server.args || [])]
|
||||||
|
|
||||||
|
|||||||
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user