mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-14 14:50:50 +08:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { ipcMain } from 'electron';
|
|
import Store from 'electron-store';
|
|
import fs from 'fs';
|
|
import server from 'netease-cloud-music-api-alger/server';
|
|
import os from 'os';
|
|
import path from 'path';
|
|
|
|
import { unblockMusic, type Platform } from './unblockMusic';
|
|
|
|
const store = new Store();
|
|
if (!fs.existsSync(path.resolve(os.tmpdir(), 'anonymous_token'))) {
|
|
fs.writeFileSync(path.resolve(os.tmpdir(), 'anonymous_token'), '', 'utf-8');
|
|
}
|
|
|
|
// 设置音乐解析的处理程序
|
|
ipcMain.handle('unblock-music', async (_event, id, songData, enabledSources) => {
|
|
try {
|
|
const result = await unblockMusic(id, songData, 1, enabledSources as Platform[]);
|
|
return result;
|
|
} catch (error) {
|
|
console.error('音乐解析失败:', error);
|
|
return { error: (error as Error).message || '未知错误' };
|
|
}
|
|
});
|
|
|
|
async function startMusicApi(): Promise<void> {
|
|
console.log('MUSIC API STARTED');
|
|
|
|
const port = (store.get('set') as any).musicApiPort || 30488;
|
|
|
|
await server.serveNcmApi({
|
|
port
|
|
});
|
|
}
|
|
|
|
export { startMusicApi };
|