mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-14 14:50:50 +08:00
feat: electron only
This commit is contained in:
@@ -40,14 +40,7 @@ export default defineConfig({
|
|||||||
],
|
],
|
||||||
publicDir: resolve('resources'),
|
publicDir: resolve('resources'),
|
||||||
server: {
|
server: {
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0'
|
||||||
proxy: {
|
|
||||||
'/kugou': {
|
|
||||||
target: 'http://msearchcdn.kugou.com', // 目标服务器地址
|
|
||||||
changeOrigin: true, // 必须设置为 true
|
|
||||||
rewrite: (path) => path.replace(/^\/kugou/, '') // 重写请求路径,去掉 /kugou 前缀
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -275,6 +275,28 @@ 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 [];
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
1
src/preload/index.d.ts
vendored
1
src/preload/index.d.ts
vendored
@@ -22,6 +22,7 @@ interface API {
|
|||||||
onLanguageChanged: (callback: (locale: string) => void) => void;
|
onLanguageChanged: (callback: (locale: string) => void) => void;
|
||||||
removeDownloadListeners: () => void;
|
removeDownloadListeners: () => void;
|
||||||
invoke: (channel: string, ...args: any[]) => Promise<any>;
|
invoke: (channel: string, ...args: any[]) => Promise<any>;
|
||||||
|
getSearchSuggestions: (keyword: string) => Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自定义IPC渲染进程通信接口
|
// 自定义IPC渲染进程通信接口
|
||||||
|
|||||||
@@ -54,7 +54,9 @@ const api = {
|
|||||||
return ipcRenderer.invoke(channel, ...args);
|
return ipcRenderer.invoke(channel, ...args);
|
||||||
}
|
}
|
||||||
return Promise.reject(new Error(`未授权的 IPC 通道: ${channel}`));
|
return Promise.reject(new Error(`未授权的 IPC 通道: ${channel}`));
|
||||||
}
|
},
|
||||||
|
// 搜索建议
|
||||||
|
getSearchSuggestions: (keyword: string) => ipcRenderer.invoke('get-search-suggestions', keyword),
|
||||||
};
|
};
|
||||||
|
|
||||||
// 创建带类型的ipcRenderer对象,暴露给渲染进程
|
// 创建带类型的ipcRenderer对象,暴露给渲染进程
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
import axios from 'axios';
|
import { isElectron } from '@/utils';
|
||||||
|
|
||||||
interface IParams {
|
interface IParams {
|
||||||
keywords: string;
|
keywords: string;
|
||||||
@@ -39,15 +39,16 @@ export const getSearchSuggestions = async (keyword: string) => {
|
|||||||
console.log(`[API] getSearchSuggestions: 准备请求,关键词: "${keyword}"`);
|
console.log(`[API] getSearchSuggestions: 准备请求,关键词: "${keyword}"`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get<KugouSuggestionResponse>('/kugou/new/app/i/search.php', {
|
let responseData: KugouSuggestionResponse;
|
||||||
params: {
|
if (isElectron) {
|
||||||
cmd: 302,
|
console.log('[API] Running in Electron, using IPC proxy.');
|
||||||
keyword: keyword,
|
responseData = await window.api.getSearchSuggestions(keyword);
|
||||||
},
|
} else {
|
||||||
});
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
if (response.data && Array.isArray(response.data.data)) {
|
if (responseData && Array.isArray(responseData.data)) {
|
||||||
const suggestions = response.data.data.map(item => item.keyword).slice(0, 8);
|
const suggestions = responseData.data.map(item => item.keyword).slice(0, 10);
|
||||||
console.log('[API] getSearchSuggestions: 成功解析建议:', suggestions);
|
console.log('[API] getSearchSuggestions: 成功解析建议:', suggestions);
|
||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user