refactor: 架构整固——分层单向化、全量 TypeScript、直接运行

- 移除 bd/mg 两平台及磁盘残留产物;清理 api-test 死脚本、musicSdk/message+options 死模块、infSign vendor
- musicSdk/ 改名 sdk/;src/common、src/auth、src/apis 整体移入 sdk/,依赖方向定为 src → sdk 严格单向
- src/ 手写 JS 全量转 .ts,删除 JS 类型垫片 modules.d.ts;源码 import 统一 .ts 后缀
- Node 原生类型剥离直接运行 .ts(engines >=22.18),取消 tsc 发射产物,tsc 仅类型检查(pnpm typecheck)
- 删除 kwdes 备用实现与 src/index.ts 转发垫片;测试移至 test/smoke-test.ts
- common/request.ts 补显式导出类型;修复 set-cookie 单值形态、ApiError 类字段等隐患

验证:tsc 零错误,smoke-test 41/41
This commit is contained in:
snowy-yang committed 2026-09-25 23:06:23 +08:00
1 parent c8c939aa32
commit 354df2e739
126 files changed
+413 -2942

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
import crypto from 'node:crypto'
const PART_1_INDEXES = [23, 14, 6, 36, 16, 40, 7, 19]
const PART_2_INDEXES = [16, 1, 32, 12, 19, 27, 8, 5]
const SCRAMBLE_VALUES = [89, 39, 179, 150, 218, 82, 58, 252, 177, 52, 186, 123, 120, 64, 242, 133, 143, 161, 121, 179]
async function hashSHA1(data) {
return crypto.createHash('sha1').update(data).digest('hex')
}
function pickHashByIdx(hash, indexes) {
return indexes.map((idx) => hash[idx]).join('')
}
function base64Encode(data) {
return Buffer.from(data)
.toString('base64')
.replace(/[\\/+=]/g, '')
}
export async function zzcSign(text) {
const hash = await hashSHA1(text)
const part1 = pickHashByIdx(hash, PART_1_INDEXES)
const part2 = pickHashByIdx(hash, PART_2_INDEXES)
const part3 = SCRAMBLE_VALUES.map((value, i) => value ^ parseInt(hash.slice(i * 2, i * 2 + 2), 16))
const b64Part = base64Encode(part3).replace(/[\\/+=]/g, '')
return `zzc${part1}${b64Part}${part2}`.toLowerCase()
}
+45
View File
@@ -0,0 +1,45 @@
import type { HttpRequestObject } from '../../types.ts'
import { httpFetch } from '../../request.ts'
import { zzcSign } from './crypto.ts'
export const signRequest = async(data) => {
// console.log(data)
const sign = await zzcSign(JSON.stringify(data))
// console.log('sign', sign)
return httpFetch(`https://u.y.qq.com/cgi-bin/musics.fcg?sign=${sign}`, {
method: 'post',
headers: {
'User-Agent': 'QQMusic 14090508(android 12)',
},
body: data,
}).promise
}
/**
* musicu.fcg 通用请求(comm 参数对齐榜单模块的可用配置;
* musichallSinger/musichallAlbum 的部分详情接口在该通道已停用,见各模块说明)
*/
export const createMusicuFetch = async(data, retryNum = 0) => {
if (retryNum > 2) throw new Error('try max num')
let result
try {
result = await httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
method: 'post',
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
},
body: {
comm: { uin: 0, format: 'json', ct: 20, cv: 1859 },
...data,
},
}).promise
} catch (err) {
console.log(err)
return createMusicuFetch(data, ++retryNum)
}
if (result.statusCode !== 200 || result.body.code != 0) return createMusicuFetch(data, ++retryNum)
return result.body
}