mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-24 08:07:23 +08:00
fix: electron环境使用kg, 其他环境使用 wy api,独立kg搜索提示 API 到otherApi.ts
This commit is contained in:
@@ -16,6 +16,7 @@ import { setupUpdateHandlers } from './modules/update';
|
||||
import { createMainWindow, initializeWindowManager, setAppQuitting } from './modules/window';
|
||||
import { initWindowSizeManager } from './modules/window-size';
|
||||
import { startMusicApi } from './server';
|
||||
import { initializeOtherApi } from './modules/otherApi';
|
||||
|
||||
// 导入所有图标
|
||||
const iconPath = join(__dirname, '../../resources');
|
||||
@@ -38,6 +39,8 @@ function initialize() {
|
||||
|
||||
// 初始化文件管理
|
||||
initializeFileManager();
|
||||
// 初始化其他 API (搜索建议等)
|
||||
initializeOtherApi();
|
||||
// 初始化窗口管理
|
||||
initializeWindowManager();
|
||||
// 初始化字体管理
|
||||
|
||||
@@ -275,28 +275,6 @@ export function initializeFileManager() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 搜索建议
|
||||
ipcMain.handle('get-search-suggestions', async (_, keyword: string) => {
|
||||
if (!keyword || !keyword.trim()) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
console.log(`[Main Process Proxy] Forwarding suggestion request for: ${keyword}`);
|
||||
const response = await axios.get('http://msearchcdn.kugou.com/new/app/i/search.php', {
|
||||
params: {
|
||||
cmd: 302,
|
||||
keyword: keyword,
|
||||
},
|
||||
timeout: 5000
|
||||
});
|
||||
return response.data;
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[Main Process Proxy] Failed to fetch search suggestions:', error.message);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import axios from 'axios';
|
||||
import { ipcMain } from 'electron';
|
||||
|
||||
/**
|
||||
* 初始化其他杂项 API(如搜索建议等)
|
||||
*/
|
||||
export function initializeOtherApi() {
|
||||
// 搜索建议(从酷狗获取)
|
||||
ipcMain.handle('get-search-suggestions', async (_, keyword: string) => {
|
||||
if (!keyword || !keyword.trim()) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
console.log(`[Main Process Proxy] Forwarding suggestion request for: ${keyword}`);
|
||||
const response = await axios.get('http://msearchcdn.kugou.com/new/app/i/search.php', {
|
||||
params: {
|
||||
cmd: 302,
|
||||
keyword: keyword
|
||||
},
|
||||
timeout: 5000
|
||||
});
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error('[Main Process Proxy] Failed to fetch search suggestions:', error.message);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user