refactor(sdk): tipSearch 全删、歌词解码器归位、IPC 桥移除、api-source 层拆除

- 四平台 tipSearch 全部删除(永不做搜索联想),types 同步去掉 tipSearch 字段
- 歌词解码器归位:kg/krcDecode、tx/qrcDecode、kw/lyricDecode(原 common/ 下三处)
- rendererIpc/ipcNames IPC 桥删除,SDK 纯服务端化
- supportQuality 由各平台 apis 内联导出(sdk/index 汇总),kg/kw/tx/wy 改直连 apis/*,api-source 旧层移除
This commit is contained in:
snowy-yang committed 2026-10-01 16:33:53 +08:00
1 parent 3c51e4d06a
commit 66d06ef48a
25 files changed
+42 -342

No files matched your search

+2 -4
View File
@@ -1,11 +1,10 @@
import { httpFetch } from '../request.ts'
import tipSearch from './tipSearch.ts'
import musicSearch from './musicSearch.ts'
import { formatSinger } from './util.ts'
import leaderboard from './leaderboard.ts'
import lyric from './lyric.ts'
import pic from './pic.ts'
import { apis } from '../api-source.ts'
import kwApi from '../apis/kw.ts'
import songList from './songList.ts'
import hotSearch from './hotSearch.ts'
import comment from './comment.ts'
@@ -35,7 +34,6 @@ const kw = {
// // })
// },
tipSearch,
musicSearch,
leaderboard,
songList,
@@ -63,7 +61,7 @@ const kw = {
},
getMusicUrl(songInfo, type) {
return apis('kw').getMusicUrl!(songInfo, type)
return kwApi.getMusicUrl(songInfo, type)
},
getMusicInfo(songInfo) {
+48
View File
@@ -0,0 +1,48 @@
// 酷我歌词解码(原主进程 IPC 处理器的纯 JS 实现)
// - 酷我歌词(inflate + yeelion XOR + gb18030)
// 算法来源: kw 桌面端歌词解码实现
import zlib from 'node:zlib'
import iconv from 'iconv-lite'
const handleInflate = (data: Buffer): Promise<Buffer> => new Promise((resolve, reject) => {
zlib.inflate(data, (err, result) => {
if (err) return reject(err)
resolve(result)
})
})
const buf_key = Buffer.from('yeelion')
const buf_key_len = buf_key.length
const decodeKwLyric = async(buf, isGetLyricx) => {
if (buf.toString('utf8', 0, 10) != 'tp=content') return ''
const lrcData = await handleInflate(buf.subarray(buf.indexOf('\r\n\r\n') + 4))
if (!isGetLyricx) return iconv.decode(lrcData, 'gb18030')
const buf_str = Buffer.from(lrcData.toString(), 'base64')
const buf_str_len = buf_str.length
const output = new Uint8Array(buf_str_len)
let i = 0
while (i < buf_str_len) {
let j = 0
while (j < buf_key_len && i < buf_str_len) {
output[i] = buf_str[i] ^ buf_key[j]
i++
j++
}
}
return iconv.decode(Buffer.from(output), 'gb18030')
}
/**
* 酷我歌词解码
* @param {{ lrcBase64: string, isGetLyricx: boolean }} params
* @returns {Promise<string>} 解码后歌词的 base64
*/
export const handleKwDecodeLyric = async({ lrcBase64, isGetLyricx }) => {
const lrc = await decodeKwLyric(Buffer.from(lrcBase64, 'base64'), isGetLyricx)
return Buffer.from(lrc).toString('base64')
}
-35
View File
@@ -1,35 +0,0 @@
// import { decodeName } from '../index.ts'
// import { tokenRequest } from './util.ts'
import { httpFetch } from '../request.ts'
import type { HttpRequestObject } from '../types.ts'
export default {
regExps: {
relWord: /RELWORD=(.+)/,
},
requestObj: null as HttpRequestObject | null,
async tipSearchBySong(str: string) {
// 报错403,加了referer还是有问题(直接换一个
// this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`)
this.cancelTipSearch()
this.requestObj = httpFetch(`https://tips.kuwo.cn/t.s?corp=kuwo&newver=3&p2p=1&notrace=0&c=mbox&w=${encodeURIComponent(str)}&encoding=utf8&rformat=json`, {
headers: {
Referer: 'http://www.kuwo.cn/',
},
})
return this.requestObj!.promise.then(({ body, statusCode }) => {
if (statusCode != 200 || !body.WORDITEMS) return Promise.reject(new Error('请求失败'))
return body.WORDITEMS
})
},
handleResult(rawData: any) {
return rawData.map(item => item.RELWORD)
},
cancelTipSearch() {
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
},
async search(str: string) {
return this.tipSearchBySong(str).then(result => this.handleResult(result))
},
}
+2 -4
View File
@@ -1,6 +1,5 @@
// import { httpGet, httpFetch } from '../request.ts'
import { WIN_MAIN_RENDERER_EVENT_NAME } from '../common/ipcNames.ts'
import { rendererInvoke } from '../common/rendererIpc.ts'
import { handleKwDecodeLyric } from './lyricDecode.ts'
import { createCipheriv, createDecipheriv } from 'crypto'
import { toMD5 } from '../utils.ts'
@@ -63,8 +62,7 @@ export const matchToken = (headers: Record<string, any>): string | null => {
// })
// })
export const decodeLyric = (base64Data: { lrcBase64: string; isGetLyricx: boolean }): Promise<any> =>
rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.handle_kw_decode_lyric, base64Data)
export const decodeLyric = handleKwDecodeLyric
// export const tokenRequest = async(url, options = {}) => {
// let token = kw_token.token