refactor(sdk): musicSdk 全量迁移至 TypeScript
This commit is contained in:
1 parent
f289df4cd7
commit
1dfb7a59ca
83 files changed
+924
-732
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
|
||||
export default {
|
||||
_requestObj: null,
|
||||
_requestObj: null as HttpRequestObject | null,
|
||||
async getList(retryNum = 0) {
|
||||
if (this._requestObj) this._requestObj.cancelHttp()
|
||||
if (retryNum > 2) return Promise.reject(new Error('try max num'))
|
||||
@@ -1,10 +1,10 @@
|
||||
import leaderboard from './leaderboard.js'
|
||||
import { apis } from '../api-source.js'
|
||||
import musicInfo from './musicInfo.js'
|
||||
import songList from './songList.js'
|
||||
import { httpFetch } from '../request.js'
|
||||
import musicSearch from './musicSearch.js'
|
||||
import hotSearch from './hotSearch.js'
|
||||
import leaderboard from './leaderboard.ts'
|
||||
import { apis } from '../api-source.ts'
|
||||
import musicInfo from './musicInfo.ts'
|
||||
import songList from './songList.ts'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import musicSearch from './musicSearch.ts'
|
||||
import hotSearch from './hotSearch.ts'
|
||||
|
||||
const bd = {
|
||||
leaderboard,
|
||||
@@ -12,7 +12,7 @@ const bd = {
|
||||
musicSearch,
|
||||
hotSearch,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('bd').getMusicUrl(songInfo, type)
|
||||
return apis('bd').getMusicUrl!(songInfo, type)
|
||||
},
|
||||
getPic(songInfo) {
|
||||
const requestObj = this.getMusicInfo(songInfo)
|
||||
@@ -1,4 +1,4 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
// import { formatPlayTime } from '../index.js'
|
||||
|
||||
|
||||
@@ -86,8 +86,8 @@ export default {
|
||||
filterData(rawList) {
|
||||
// console.log(rawList)
|
||||
return rawList.map(item => {
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: any[] = []
|
||||
const _types: Record<string, any> = {}
|
||||
let size = null
|
||||
types.push({ type: '128k', size })
|
||||
_types['128k'] = {
|
||||
@@ -1,4 +1,4 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
|
||||
export default {
|
||||
cache: {},
|
||||
@@ -1,7 +1,7 @@
|
||||
// import '../../polyfill/array.find.js'
|
||||
|
||||
import { httpFetch } from '../request.js'
|
||||
import { formatPlayTime } from '../index.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { formatPlayTime } from '../index.ts'
|
||||
// import { debug } from '../../utils/env.js'
|
||||
// import { formatSinger } from './util.js'
|
||||
|
||||
@@ -16,13 +16,13 @@ export default {
|
||||
},
|
||||
handleResult(rawData) {
|
||||
let ids = new Set()
|
||||
const list = []
|
||||
const list: any[] = []
|
||||
if (!rawData) return list
|
||||
rawData.forEach(item => {
|
||||
if (ids.has(item.song_id)) return
|
||||
ids.add(item.song_id)
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: any[] = []
|
||||
const _types: Record<string, any> = {}
|
||||
let size = null
|
||||
let itemTypes = item.all_rate.split(',')
|
||||
if (itemTypes.includes('128')) {
|
||||
@@ -1,12 +1,13 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { formatPlayTime } from '../index.js'
|
||||
import { toMD5 } from '../utils.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { formatPlayTime } from '../index.ts'
|
||||
import { toMD5 } from '../utils.ts'
|
||||
import CryptoJS from 'crypto-js'
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
|
||||
export default {
|
||||
_requestObj_tags: null,
|
||||
_requestObj_list: null,
|
||||
_requestObj_listRecommend: null,
|
||||
_requestObj_tags: null as HttpRequestObject | null,
|
||||
_requestObj_list: null as HttpRequestObject | null,
|
||||
_requestObj_listRecommend: null as HttpRequestObject | null,
|
||||
limit_list: 30,
|
||||
limit_song: 10000,
|
||||
successCode: 22000,
|
||||
@@ -29,7 +30,7 @@ export default {
|
||||
let privateKey = toMD5('baidu_taihe_music_secret_key' + timestamp).substr(8, 16)
|
||||
let key = CryptoJS.enc.Utf8.parse(privateKey)
|
||||
let iv = CryptoJS.enc.Utf8.parse(privateKey)
|
||||
let arrData = []
|
||||
let arrData: string[] = []
|
||||
let strData = ''
|
||||
for (let key in jsonData) arrData.push(key)
|
||||
arrData.sort()
|
||||
@@ -40,7 +41,7 @@ export default {
|
||||
}
|
||||
let JsonFormatter = {
|
||||
stringify(cipherParams) {
|
||||
let jsonObj = {
|
||||
let jsonObj: Record<string, any> = {
|
||||
ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64),
|
||||
}
|
||||
if (cipherParams.iv) {
|
||||
@@ -116,7 +117,7 @@ export default {
|
||||
if (this._requestObj_tags) this._requestObj_tags.cancelHttp()
|
||||
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
||||
this._requestObj_tags = httpFetch(this.getTagsUrl())
|
||||
return this._requestObj_tags.promise.then(({ body }) => {
|
||||
return this._requestObj_tags!.promise.then(({ body }) => {
|
||||
if (body.error_code !== this.successCode) return this.getTags(++tryNum)
|
||||
return {
|
||||
hotTag: this.filterInfoHotTag(body.result.hot),
|
||||
@@ -150,7 +151,7 @@ export default {
|
||||
if (this._requestObj_list) this._requestObj_list.cancelHttp()
|
||||
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
||||
this._requestObj_list = httpFetch(this.getListUrl(sortId, tagId, page))
|
||||
return this._requestObj_list.promise.then(({ body }) => {
|
||||
return this._requestObj_list!.promise.then(({ body }) => {
|
||||
if (body.error_code !== this.successCode) return this.getList(sortId, tagId, page, ++tryNum)
|
||||
return {
|
||||
list: this.filterList(body.diyInfo),
|
||||
@@ -168,8 +169,8 @@ export default {
|
||||
* @param {*} num
|
||||
*/
|
||||
formatPlayCount(num) {
|
||||
if (num > 100000000) return parseInt(num / 10000000) / 10 + '亿'
|
||||
if (num > 10000) return parseInt(num / 1000) / 10 + '万'
|
||||
if (num > 100000000) return parseInt((num / 10000000) as any) / 10 + '亿'
|
||||
if (num > 10000) return parseInt((num / 1000) as any) / 10 + '万'
|
||||
return num
|
||||
},
|
||||
filterList(rawData) {
|
||||
@@ -215,8 +216,8 @@ export default {
|
||||
filterData(rawList) {
|
||||
// console.log(rawList)
|
||||
return rawList.map(item => {
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: any[] = []
|
||||
const _types: Record<string, any> = {}
|
||||
let size = null
|
||||
let itemTypes = item.all_rate.split(',')
|
||||
if (itemTypes.includes('128')) {
|
||||
Reference in new issue
Block a user