refactor(api)!: 平台 id 改两字母短码——qian→bd、joox→jx、5sing→5s、bili→bl
对外 id 统一为两字母短码,与既有的 kw/kg/tx/wy/qs/xm/me/qt/lr 对齐; migu 与 apple 保持原样(Apple Music 没有自然的短码)。 **破坏性变更**:id 出现在所有 URL、/sources 返回、OpenAPI 示例以及 data/auth.json 的凭据键里,这四个平台已存的登录态会失效,需重新登录。 - sdk/index.ts:id 与 supportQuality 映射键 - sdk/types.ts:Source 联合类型 - src/routes.ts 与 routes-login.ts:路由路径与 schema 描述 (/login/bili/qr → /login/bl/qr 等)、/login/status 的响应键 - test/smoke-test.ts、README.md、docs/API.md 同步 有意未改:sdk 目录与文件名仍用平台名(sdk/qian/、sdk/apis/joox.ts …), 规则定为「目录=平台名,id=对外短码」,映射只在 SUPPORTED_SOURCES 一处声明。 域名与正则(joox.com、5sing.kugou.com、/joox\.com\//)、jooxSign 等标识符、 错误文案里的中文平台名、以及 kg 榜单名(含「joox本地热歌榜」)全部保持原样—— 它们只是恰好含平台名,并不是 id。 验证:typecheck ✓、pnpm test 112/112 ✓;另起临时实例实证 /sources 与 /login/status 的新 id 与展示名,新旧 id 均无残留。
This commit is contained in:
1 parent
14f7295fd4
commit
3381e9b906
33 files changed
+155
-155
No files matched your search
+26
-26
@@ -514,11 +514,11 @@ await test('专辑详情 /album/lr', async() => {
|
||||
return `${r.data.info.total} 节`
|
||||
})
|
||||
|
||||
// ---- 新平台(migu/qian/joox/bili/5sing/apple 移植回归) ----
|
||||
// ---- 新平台(migu/bd/jx/bl/5s/apple 移植回归) ----
|
||||
|
||||
for (const source of ['migu', 'qian', 'joox', 'bili', '5sing', 'apple']) {
|
||||
for (const source of ['migu', 'bd', 'jx', 'bl', '5s', 'apple']) {
|
||||
await test(`搜索 ${source} 直查`, async() => {
|
||||
const r = await get(`/search/${source}/${encodeURIComponent(source === '5sing' ? '董贞' : '周杰伦')}?limit=5`)
|
||||
const r = await get(`/search/${source}/${encodeURIComponent(source === '5s' ? '董贞' : '周杰伦')}?limit=5`)
|
||||
if (r.code != 0) throw new Error(r.msg)
|
||||
if (!r.data?.list?.length) throw new Error('空列表')
|
||||
return `${r.data.list.length} 条,首条 ${r.data.list[0].name}`
|
||||
@@ -536,21 +536,21 @@ await test('URL migu(多档候选链)', async() => {
|
||||
return `实际 ${u.data.type},${url.slice(0, 60)}`
|
||||
})
|
||||
|
||||
await test('URL qian 免费曲', async() => {
|
||||
// qian 免费曲目少,用「SSR」(上游测试同款厂牌)搜到带直链的曲目
|
||||
const r = await get(`/search/qian/${encodeURIComponent('SSR')}?limit=10`)
|
||||
await test('URL bd 免费曲', async() => {
|
||||
// bd 免费曲目少,用「SSR」(上游测试同款厂牌)搜到带直链的曲目
|
||||
const r = await get(`/search/bd/${encodeURIComponent('SSR')}?limit=10`)
|
||||
if (r.code != 0 || !r.data?.list?.length) throw new Error('搜索失败,无法取流')
|
||||
const song = r.data.list.find((s: any) => !s.payPlay)
|
||||
if (!song) throw new Error('未搜到免费曲目')
|
||||
const u = await get(`/url/qian/${encodeURIComponent(song.songmid)}?quality=128k`)
|
||||
const u = await get(`/url/bd/${encodeURIComponent(song.songmid)}?quality=128k`)
|
||||
if (u.code != 0) throw new Error(u.msg)
|
||||
return `实际 ${u.data.type},${String(u.data.url).slice(0, 60)}`
|
||||
})
|
||||
|
||||
await test('URL 5sing(档位 sq/hq/lq)', async() => {
|
||||
const r = await get(`/search/5sing/${encodeURIComponent('董贞')}?limit=5`)
|
||||
await test('URL 5s(档位 sq/hq/lq)', async() => {
|
||||
const r = await get(`/search/5s/${encodeURIComponent('董贞')}?limit=5`)
|
||||
if (r.code != 0 || !r.data?.list?.length) throw new Error('搜索失败,无法取流')
|
||||
const u = await get(`/url/5sing/${encodeURIComponent(r.data.list[0].songmid)}?quality=128k`)
|
||||
const u = await get(`/url/5s/${encodeURIComponent(r.data.list[0].songmid)}?quality=128k`)
|
||||
if (u.code != 0) throw new Error(u.msg)
|
||||
return `实际 ${u.data.type},${String(u.data.url).slice(0, 60)}`
|
||||
})
|
||||
@@ -565,11 +565,11 @@ await test('歌词 migu', async() => {
|
||||
return l.data.lyric.slice(0, 40)
|
||||
})
|
||||
|
||||
await test('歌词 5sing', async() => {
|
||||
const r = await get(`/search/5sing/${encodeURIComponent('董贞')}?limit=5`)
|
||||
await test('歌词 5s', async() => {
|
||||
const r = await get(`/search/5s/${encodeURIComponent('董贞')}?limit=5`)
|
||||
const song = r.data?.list?.[0]
|
||||
if (!song) throw new Error('搜索失败')
|
||||
const l = await get(`/lyric/5sing/${encodeURIComponent(song.songmid)}`)
|
||||
const l = await get(`/lyric/5s/${encodeURIComponent(song.songmid)}`)
|
||||
if (l.code != 0) throw new Error(l.msg)
|
||||
if (!l.data?.lyric) throw new Error('空歌词')
|
||||
return l.data.lyric.slice(0, 40)
|
||||
@@ -585,7 +585,7 @@ await test('封面 migu', async() => {
|
||||
return String(p.data.url).slice(0, 60)
|
||||
})
|
||||
|
||||
for (const source of ['migu', 'qian', 'joox', 'apple']) {
|
||||
for (const source of ['migu', 'bd', 'jx', 'apple']) {
|
||||
await test(`专辑搜索 /album/${source}/search`, async() => {
|
||||
const r = await get(`/album/${source}/search/${encodeURIComponent('Hello')}?limit=3`)
|
||||
if (r.code != 0) throw new Error(r.msg)
|
||||
@@ -604,7 +604,7 @@ await test('专辑详情 /album/migu', async() => {
|
||||
return `${a.data.info.name}(${a.data.total} 首)`
|
||||
})
|
||||
|
||||
for (const source of ['migu', 'qian', 'joox', 'apple']) {
|
||||
for (const source of ['migu', 'bd', 'jx', 'apple']) {
|
||||
await test(`歌单分类 /playlist/${source}/categories`, async() => {
|
||||
const r = await get(`/playlist/${source}/categories`)
|
||||
if (r.code != 0) throw new Error(r.msg)
|
||||
@@ -635,11 +635,11 @@ await test('歌单详情 /playlist/migu', async() => {
|
||||
return `${d.data.total} 首,本页 ${d.data.list.length} 首`
|
||||
})
|
||||
|
||||
await test('歌单详情 /playlist/bili(合集)', async() => {
|
||||
const s = await get(`/playlist/bili/search/${encodeURIComponent('周杰伦')}?limit=3`)
|
||||
await test('歌单详情 /playlist/bl(合集)', async() => {
|
||||
const s = await get(`/playlist/bl/search/${encodeURIComponent('周杰伦')}?limit=3`)
|
||||
const id = s.data?.list?.[0]?.id
|
||||
if (!id) throw new Error('搜索无歌单')
|
||||
const d = await get(`/playlist/bili/${encodeURIComponent(id)}?limit=5`)
|
||||
const d = await get(`/playlist/bl/${encodeURIComponent(id)}?limit=5`)
|
||||
if (d.code != 0) throw new Error(d.msg)
|
||||
if (!d.data?.list?.length) throw new Error('歌单无曲目')
|
||||
return `${d.data.total} 首`
|
||||
@@ -652,8 +652,8 @@ await test('链接解析 /parse/song/migu', async() => {
|
||||
return `${r.body.data.song.name} / ${r.body.data.song.singer}`
|
||||
})
|
||||
|
||||
await test('链接解析 /parse/playlist/qian', async() => {
|
||||
const r = await postJson('/parse/playlist/qian', { link: 'https://music.91q.com/songlist/309735' })
|
||||
await test('链接解析 /parse/playlist/bd', async() => {
|
||||
const r = await postJson('/parse/playlist/bd', { link: 'https://music.91q.com/songlist/309735' })
|
||||
if (r.status !== 200 || r.body?.code != 0) throw new Error(JSON.stringify(r.body).slice(0, 120))
|
||||
if (!r.body.data?.list?.length) throw new Error('无曲目')
|
||||
return `${r.body.data.playlist?.name ?? ''}(${r.body.data.total} 首)`
|
||||
@@ -682,24 +682,24 @@ await test('链接解析 /parse/song/kw(正向)', async() => {
|
||||
return `kw 解析成功: ${r.body.data.song.name}`
|
||||
})
|
||||
|
||||
await test('扫码二维码创建 POST /login/bili/qr', async() => {
|
||||
const r = await postRaw('/login/bili/qr')
|
||||
await test('扫码二维码创建 POST /login/bl/qr', async() => {
|
||||
const r = await postRaw('/login/bl/qr')
|
||||
const body = JSON.parse(r.body)
|
||||
if (r.status !== 200 || body.code != 0 || !body.data?.key) throw new Error(r.body.slice(0, 120))
|
||||
return `key=${String(body.data.key).slice(0, 12)}…`
|
||||
})
|
||||
|
||||
await test('扫码轮询 POST /login/bili/qr/check', async() => {
|
||||
const created = JSON.parse((await postRaw('/login/bili/qr')).body)
|
||||
await test('扫码轮询 POST /login/bl/qr/check', async() => {
|
||||
const created = JSON.parse((await postRaw('/login/bl/qr')).body)
|
||||
const key = created.data?.key
|
||||
if (!key) throw new Error('未取到 key')
|
||||
const r = await postJson('/login/bili/qr/check', { key })
|
||||
const r = await postJson('/login/bl/qr/check', { key })
|
||||
if (r.status !== 200 || r.body?.code != 0) throw new Error(JSON.stringify(r.body).slice(0, 120))
|
||||
return `status=${r.body.data.status} code=${r.body.data.code}`
|
||||
})
|
||||
|
||||
await test('个人歌单 未支持的平台 → 502', async() => {
|
||||
const r = await getRaw('/user-playlist/5sing')
|
||||
const r = await getRaw('/user-playlist/5s')
|
||||
if (r.status !== 502 && r.status !== 404) throw new Error(`期望 502/404,实际 ${r.status}`)
|
||||
return JSON.parse(r.body).msg?.slice(0, 60)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user