refactor(sdk): musicSdk 全量迁移至 TypeScript
This commit is contained in:
1 parent
f289df4cd7
commit
1dfb7a59ca
83 files changed
+924
-732
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { httpFetch } from '../request.ts'
|
||||
import getSongId from './songId.ts'
|
||||
|
||||
export default {
|
||||
async getPicUrl(songId, tryNum = 0) {
|
||||
let requestObj = httpFetch(`http://music.migu.cn/v3/api/music/audioPlayer/getSongPic?songId=${songId}`, {
|
||||
headers: {
|
||||
Referer: 'http://music.migu.cn/v3/music/player/audio?from=migu',
|
||||
},
|
||||
})
|
||||
requestObj.promise.then(({ body }) => {
|
||||
if (body.returnCode !== '000000') {
|
||||
if (tryNum > 5) return Promise.reject(new Error('图片获取失败'))
|
||||
let tryRequestObj = (this as any).getPic(songId, ++tryNum)
|
||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
let url = body.largePic || body.mediumPic || body.smallPic
|
||||
if (!/https?:/.test(url)) url = 'http:' + url
|
||||
return url
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
async getPic(songInfo) {
|
||||
const songId = await getSongId(songInfo)
|
||||
return this.getPicUrl(songId)
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user