mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-02 18:39:06 +08:00
fix: remove redundant local variables (#5654)
This commit is contained in:
parent
5ceb2af056
commit
f258f5b2cb
@ -237,8 +237,7 @@ async function getPoisData(apiKey: string, ids: string[]): Promise<BravePoiRespo
|
|||||||
throw new Error(`Brave API error: ${response.status} ${response.statusText}\n${await response.text()}`)
|
throw new Error(`Brave API error: ${response.status} ${response.statusText}\n${await response.text()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const poisResponse = (await response.json()) as BravePoiResponse
|
return (await response.json()) as BravePoiResponse
|
||||||
return poisResponse
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDescriptionsData(apiKey: string, ids: string[]): Promise<BraveDescription> {
|
async function getDescriptionsData(apiKey: string, ids: string[]): Promise<BraveDescription> {
|
||||||
@ -257,8 +256,7 @@ async function getDescriptionsData(apiKey: string, ids: string[]): Promise<Brave
|
|||||||
throw new Error(`Brave API error: ${response.status} ${response.statusText}\n${await response.text()}`)
|
throw new Error(`Brave API error: ${response.status} ${response.statusText}\n${await response.text()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const descriptionsData = (await response.json()) as BraveDescription
|
return (await response.json()) as BraveDescription
|
||||||
return descriptionsData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatLocalResults(poisData: BravePoiResponse, descData: BraveDescription): string {
|
function formatLocalResults(poisData: BravePoiResponse, descData: BraveDescription): string {
|
||||||
|
|||||||
@ -209,20 +209,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||||||
const validatedArgs = RequestPayloadSchema.parse(args)
|
const validatedArgs = RequestPayloadSchema.parse(args)
|
||||||
|
|
||||||
if (request.params.name === 'fetch_html') {
|
if (request.params.name === 'fetch_html') {
|
||||||
const fetchResult = await Fetcher.html(validatedArgs)
|
return await Fetcher.html(validatedArgs)
|
||||||
return fetchResult
|
|
||||||
}
|
}
|
||||||
if (request.params.name === 'fetch_json') {
|
if (request.params.name === 'fetch_json') {
|
||||||
const fetchResult = await Fetcher.json(validatedArgs)
|
return await Fetcher.json(validatedArgs)
|
||||||
return fetchResult
|
|
||||||
}
|
}
|
||||||
if (request.params.name === 'fetch_txt') {
|
if (request.params.name === 'fetch_txt') {
|
||||||
const fetchResult = await Fetcher.txt(validatedArgs)
|
return await Fetcher.txt(validatedArgs)
|
||||||
return fetchResult
|
|
||||||
}
|
}
|
||||||
if (request.params.name === 'fetch_markdown') {
|
if (request.params.name === 'fetch_markdown') {
|
||||||
const fetchResult = await Fetcher.markdown(validatedArgs)
|
return await Fetcher.markdown(validatedArgs)
|
||||||
return fetchResult
|
|
||||||
}
|
}
|
||||||
throw new Error('Tool not found')
|
throw new Error('Tool not found')
|
||||||
})
|
})
|
||||||
|
|||||||
@ -183,7 +183,6 @@ async function searchFiles(
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Skip invalid paths during search
|
// Skip invalid paths during search
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,8 +55,8 @@ class SequentialThinkingServer {
|
|||||||
const { thoughtNumber, totalThoughts, thought, isRevision, revisesThought, branchFromThought, branchId } =
|
const { thoughtNumber, totalThoughts, thought, isRevision, revisesThought, branchFromThought, branchId } =
|
||||||
thoughtData
|
thoughtData
|
||||||
|
|
||||||
let prefix = ''
|
let prefix: string
|
||||||
let context = ''
|
let context: string
|
||||||
|
|
||||||
if (isRevision) {
|
if (isRevision) {
|
||||||
prefix = chalk.yellow('🔄 Revision')
|
prefix = chalk.yellow('🔄 Revision')
|
||||||
|
|||||||
@ -83,7 +83,7 @@ export class ExportService {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'text':
|
case 'text':
|
||||||
runs.push(new TextRun({ text: token.content, bold: isHeaderRow ? true : false }))
|
runs.push(new TextRun({ text: token.content, bold: isHeaderRow }))
|
||||||
break
|
break
|
||||||
case 'strong':
|
case 'strong':
|
||||||
runs.push(new TextRun({ text: token.content, bold: true }))
|
runs.push(new TextRun({ text: token.content, bold: true }))
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export class GeminiService {
|
|||||||
|
|
||||||
static async uploadFile(_: Electron.IpcMainInvokeEvent, file: FileType, apiKey: string): Promise<File> {
|
static async uploadFile(_: Electron.IpcMainInvokeEvent, file: FileType, apiKey: string): Promise<File> {
|
||||||
const sdk = new GoogleGenAI({ vertexai: false, apiKey })
|
const sdk = new GoogleGenAI({ vertexai: false, apiKey })
|
||||||
const uploadResult = await sdk.files.upload({
|
return await sdk.files.upload({
|
||||||
file: file.path,
|
file: file.path,
|
||||||
config: {
|
config: {
|
||||||
mimeType: 'application/pdf',
|
mimeType: 'application/pdf',
|
||||||
@ -18,7 +18,6 @@ export class GeminiService {
|
|||||||
displayName: file.origin_name
|
displayName: file.origin_name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return uploadResult
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async base64File(_: Electron.IpcMainInvokeEvent, file: FileType) {
|
static async base64File(_: Electron.IpcMainInvokeEvent, file: FileType) {
|
||||||
|
|||||||
@ -429,13 +429,12 @@ class McpService {
|
|||||||
const client = await this.initClient(server)
|
const client = await this.initClient(server)
|
||||||
try {
|
try {
|
||||||
const { prompts } = await client.listPrompts()
|
const { prompts } = await client.listPrompts()
|
||||||
const serverPrompts = prompts.map((prompt: any) => ({
|
return prompts.map((prompt: any) => ({
|
||||||
...prompt,
|
...prompt,
|
||||||
id: `p${nanoid()}`,
|
id: `p${nanoid()}`,
|
||||||
serverId: server.id,
|
serverId: server.id,
|
||||||
serverName: server.name
|
serverName: server.name
|
||||||
}))
|
}))
|
||||||
return serverPrompts
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`[MCP] Failed to list prompts for server: ${server.name}`, error)
|
Logger.error(`[MCP] Failed to list prompts for server: ${server.name}`, error)
|
||||||
return []
|
return []
|
||||||
|
|||||||
@ -32,10 +32,9 @@ interface WebDAVResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getNutstoreSSOUrl() {
|
export async function getNutstoreSSOUrl() {
|
||||||
const url = await createOAuthUrl({
|
return await createOAuthUrl({
|
||||||
app: 'cherrystudio'
|
app: 'cherrystudio'
|
||||||
})
|
})
|
||||||
return url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function decryptToken(token: string) {
|
export async function decryptToken(token: string) {
|
||||||
|
|||||||
@ -129,12 +129,11 @@ export class ProxyManager {
|
|||||||
if (!protocol.includes('socks')) {
|
if (!protocol.includes('socks')) {
|
||||||
setGlobalDispatcher(new ProxyAgent(proxyUrl))
|
setGlobalDispatcher(new ProxyAgent(proxyUrl))
|
||||||
} else {
|
} else {
|
||||||
const dispatcher = socksDispatcher({
|
global[Symbol.for('undici.globalDispatcher.1')] = socksDispatcher({
|
||||||
port: parseInt(port),
|
port: parseInt(port),
|
||||||
type: protocol === 'socks5' ? 5 : 4,
|
type: protocol === 'socks5' ? 5 : 4,
|
||||||
host: host
|
host: host
|
||||||
})
|
})
|
||||||
global[Symbol.for('undici.globalDispatcher.1')] = dispatcher
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,8 +74,7 @@ export class SearchService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Get the page content after ensuring it's fully loaded
|
// Get the page content after ensuring it's fully loaded
|
||||||
const content = await window.webContents.executeJavaScript('document.documentElement.outerHTML')
|
return await window.webContents.executeJavaScript('document.documentElement.outerHTML')
|
||||||
return content
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ export class CallBackServer {
|
|||||||
Logger.error('OAuth callback server error:', error)
|
Logger.error('OAuth callback server error:', error)
|
||||||
})
|
})
|
||||||
|
|
||||||
const runningServer = new Promise<http.Server>((resolve, reject) => {
|
return new Promise<http.Server>((resolve, reject) => {
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
Logger.info(`OAuth callback server listening on port ${port}`)
|
Logger.info(`OAuth callback server listening on port ${port}`)
|
||||||
resolve(server)
|
resolve(server)
|
||||||
@ -54,7 +54,6 @@ export class CallBackServer {
|
|||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return runningServer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get getServer(): Promise<http.Server> {
|
get getServer(): Promise<http.Server> {
|
||||||
|
|||||||
@ -9,14 +9,13 @@ const gunzipPromise = util.promisify(zlib.gunzip)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 压缩字符串
|
* 压缩字符串
|
||||||
* @param {string} string - 要压缩的 JSON 字符串
|
|
||||||
* @returns {Promise<Buffer>} 压缩后的 Buffer
|
* @returns {Promise<Buffer>} 压缩后的 Buffer
|
||||||
|
* @param str
|
||||||
*/
|
*/
|
||||||
export async function compress(str) {
|
export async function compress(str) {
|
||||||
try {
|
try {
|
||||||
const buffer = Buffer.from(str, 'utf-8')
|
const buffer = Buffer.from(str, 'utf-8')
|
||||||
const compressedBuffer = await gzipPromise(buffer)
|
return await gzipPromise(buffer)
|
||||||
return compressedBuffer
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Compression failed:', error)
|
logger.error('Compression failed:', error)
|
||||||
throw error
|
throw error
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user