- 移除 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
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import { getMusicInfosByList } from './musicInfo.ts'
|
|
import { createHttpFetch } from './util.ts'
|
|
|
|
export default {
|
|
/**
|
|
* 获取歌手信息
|
|
* @param {*} id
|
|
*/
|
|
getInfo(id) {
|
|
if (id == 0) throw new Error('歌手不存在') // kg源某些歌曲在歌手没被kg收录时返回的歌手id为0
|
|
return createHttpFetch(`http://mobiles.kugou.com/api/v5/singer/info?singerid=${id}`).then(body => {
|
|
if (!body) throw new Error('get singer info faild.')
|
|
|
|
return {
|
|
source: 'kg',
|
|
id: body.singerid,
|
|
info: {
|
|
name: body.singername,
|
|
desc: body.intro,
|
|
avatar: body.imgurl.replace('{size}', 480),
|
|
gender: body.grade === 1 ? 'man' : 'woman',
|
|
},
|
|
count: {
|
|
music: body.songcount,
|
|
album: body.albumcount,
|
|
},
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 获取歌手专辑列表
|
|
* @param {*} id
|
|
* @param {*} page
|
|
* @param {*} limit
|
|
*/
|
|
getAlbumList(id, page = 1, limit = 10) {
|
|
if (id == 0) throw new Error('歌手不存在')
|
|
return createHttpFetch(`http://mobiles.kugou.com/api/v5/singer/album?singerid=${id}&page=${page}&pagesize=${limit}`).then(body => {
|
|
if (!body.info) throw new Error('get singer album list faild.')
|
|
|
|
const list = this.filterAlbumList(body.info)
|
|
return {
|
|
source: 'kg',
|
|
list,
|
|
limit,
|
|
page,
|
|
total: body.total,
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 获取歌手歌曲列表
|
|
* @param {*} id
|
|
* @param {*} page
|
|
* @param {*} limit
|
|
*/
|
|
async getSongList(id, page = 1, limit = 100) {
|
|
if (id == 0) throw new Error('歌手不存在')
|
|
const body = await createHttpFetch(`http://mobiles.kugou.com/api/v5/singer/song?singerid=${id}&page=${page}&pagesize=${limit}`)
|
|
if (!body.info) throw new Error('get singer song list faild.')
|
|
|
|
const list = await getMusicInfosByList(body.info)
|
|
return {
|
|
source: 'kg',
|
|
list,
|
|
limit,
|
|
page,
|
|
total: body.total,
|
|
}
|
|
},
|
|
filterAlbumList(raw) {
|
|
return raw.map(item => {
|
|
return {
|
|
id: item.albumid,
|
|
count: item.songcount,
|
|
info: {
|
|
name: item.albumname,
|
|
author: item.singername,
|
|
img: String(item.imgurl || item.img || '').replace('{size}', '480'),
|
|
desc: item.intro,
|
|
},
|
|
}
|
|
})
|
|
},
|
|
}
|