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,11 +1,12 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import getSongId from './songId.js'
|
||||
import { dateFormat2 } from '../index.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import getSongId from './songId.ts'
|
||||
import { dateFormat2 } from '../index.ts'
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
|
||||
export default {
|
||||
_requestObj: null,
|
||||
_requestObj2: null,
|
||||
_requestObj3: null,
|
||||
_requestObj: null as HttpRequestObject | null,
|
||||
_requestObj2: null as HttpRequestObject | null,
|
||||
_requestObj3: null as HttpRequestObject | null,
|
||||
lastCommentIds: new Map(),
|
||||
async getComment(musicInfo, page = 1, limit = 20) {
|
||||
if (this._requestObj) this._requestObj.cancelHttp()
|
||||
@@ -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,12 +1,12 @@
|
||||
import { apis } from '../api-source.js'
|
||||
import leaderboard from './leaderboard.js'
|
||||
import songList from './songList.js'
|
||||
import musicSearch from './musicSearch.js'
|
||||
import pic from './pic.js'
|
||||
import lyric from './lyric.js'
|
||||
import hotSearch from './hotSearch.js'
|
||||
import comment from './comment.js'
|
||||
// import tipSearch from './tipSearch.js'
|
||||
import { apis } from '../api-source.ts'
|
||||
import leaderboard from './leaderboard.ts'
|
||||
import songList from './songList.ts'
|
||||
import musicSearch from './musicSearch.ts'
|
||||
import pic from './pic.ts'
|
||||
import lyric from './lyric.ts'
|
||||
import hotSearch from './hotSearch.ts'
|
||||
import comment from './comment.ts'
|
||||
// import tipSearch from './tipSearch.ts'
|
||||
|
||||
const mg = {
|
||||
// tipSearch,
|
||||
@@ -16,7 +16,7 @@ const mg = {
|
||||
hotSearch,
|
||||
comment,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('mg').getMusicUrl(songInfo, type)
|
||||
return apis('mg').getMusicUrl!(songInfo, type)
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
return lyric.getLyric(songInfo)
|
||||
@@ -1,5 +1,6 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { filterMusicInfoList } from './musicInfo.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { filterMusicInfoList } from './musicInfo.ts'
|
||||
import type { Source, HttpRequestObject } from '../types.ts'
|
||||
|
||||
// const boardList = [{ id: 'mg__27553319', name: '咪咕尖叫新歌榜', bangid: '27553319' }, { id: 'mg__27186466', name: '咪咕尖叫热歌榜', bangid: '27186466' }, { id: 'mg__27553408', name: '咪咕尖叫原创榜', bangid: '27553408' }, { id: 'mg__23189800', name: '咪咕港台榜', bangid: '23189800' }, { id: 'mg__23189399', name: '咪咕内地榜', bangid: '23189399' }, { id: 'mg__19190036', name: '咪咕欧美榜', bangid: '19190036' }, { id: 'mg__23189813', name: '咪咕日韩榜', bangid: '23189813' }, { id: 'mg__23190126', name: '咪咕彩铃榜', bangid: '23190126' }, { id: 'mg__15140045', name: '咪咕KTV榜', bangid: '15140045' }, { id: 'mg__15140034', name: '咪咕网络榜', bangid: '15140034' }, { id: 'mg__23217754', name: 'MV榜', bangid: '23217754' }, { id: 'mg__23218151', name: '新专辑榜', bangid: '23218151' }, { id: 'mg__21958042', name: 'iTunes榜', bangid: '21958042' }, { id: 'mg__21975570', name: 'billboard榜', bangid: '21975570' }, { id: 'mg__22272815', name: '台湾Hito中文榜', bangid: '22272815' }, { id: 'mg__22272904', name: '中国TOP排行榜', bangid: '22272904' }, { id: 'mg__22272943', name: '韩国Melon榜', bangid: '22272943' }, { id: 'mg__22273437', name: '英国UK榜', bangid: '22273437' }]
|
||||
|
||||
@@ -20,7 +21,15 @@ import { filterMusicInfoList } from './musicInfo.js'
|
||||
// // { id: 'mg__22272943', name: '韩国Melon榜', bangid: '22272943', webId: 'mnet' },
|
||||
// // { id: 'mg__22273437', name: '英国UK榜', bangid: '22273437', webId: 'uk' },
|
||||
// ]
|
||||
const boardList = [
|
||||
interface BoardItem {
|
||||
id: string
|
||||
name: string
|
||||
bangid: string
|
||||
source: Source
|
||||
// 旧数据字段,部分条目缺失(缺失时 getDetailPageUrl 拼出 undefined,与原实现一致)
|
||||
webId?: string
|
||||
}
|
||||
const boardList: BoardItem[] = [
|
||||
{
|
||||
id: 'mg__27553319',
|
||||
name: '新歌榜',
|
||||
@@ -141,9 +150,9 @@ export default {
|
||||
// return `http://m.music.migu.cn/migu/remoting/cms_list_tag?nid=${id}&pageSize=${this.limit}&pageNo=${page - 1}`
|
||||
},
|
||||
successCode: '000000',
|
||||
requestBoardsObj: null,
|
||||
requestBoardsObj: null as HttpRequestObject | null,
|
||||
getBoardsData() {
|
||||
if (this.requestBoardsObj) this._requestBoardsObj.cancelHttp()
|
||||
if (this.requestBoardsObj) (this as any)._requestBoardsObj.cancelHttp()
|
||||
this.requestBoardsObj = httpFetch('https://app.c.nf.migu.cn/pc/bmw/rank/rank-index/v1.0', {
|
||||
// this.requestBoardsObj = httpFetch('https://app.c.nf.migu.cn/MIGUM3.0/v1.0/template/rank-list/release', {
|
||||
// this.requestBoardsObj = httpFetch('https://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/indexrank.do?templateVersion=8', {
|
||||
@@ -153,7 +162,7 @@ export default {
|
||||
channel: '0146921',
|
||||
},
|
||||
})
|
||||
return this.requestBoardsObj.promise
|
||||
return this.requestBoardsObj!.promise
|
||||
},
|
||||
getData(url) {
|
||||
const requestObj = httpFetch(url)
|
||||
@@ -1,6 +1,6 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { getMusicInfo } from './musicInfo.js'
|
||||
import { decrypt } from './utils/mrc.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { getMusicInfo } from './musicInfo.ts'
|
||||
import { decrypt } from './utils/mrc.ts'
|
||||
|
||||
const mrcTools = {
|
||||
rxps: {
|
||||
@@ -11,8 +11,8 @@ const mrcTools = {
|
||||
parseLyric(str) {
|
||||
str = str.replace(/\r/g, '')
|
||||
const lines = str.split('\n')
|
||||
const lxlrcLines = []
|
||||
const lrcLines = []
|
||||
const lxlrcLines: string[] = []
|
||||
const lrcLines: string[] = []
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.length < 6) continue
|
||||
@@ -20,12 +20,12 @@ const mrcTools = {
|
||||
if (!result) continue
|
||||
|
||||
const startTime = parseInt(result[1])
|
||||
let time = startTime
|
||||
let time: any = startTime
|
||||
let ms = time % 1000
|
||||
time /= 1000
|
||||
let m = parseInt(time / 60).toString().padStart(2, '0')
|
||||
let m = parseInt((time / 60) as unknown as string).toString().padStart(2, '0')
|
||||
time %= 60
|
||||
let s = parseInt(time).toString().padStart(2, '0')
|
||||
let s = parseInt(time as unknown as string).toString().padStart(2, '0')
|
||||
time = `${m}:${s}.${ms}`
|
||||
|
||||
let words = line.replace(this.rxps.lineTime, '')
|
||||
@@ -36,7 +36,7 @@ const mrcTools = {
|
||||
if (!times) continue
|
||||
times = times.map(time => {
|
||||
const result = /\((\d+),(\d+)\)/.exec(time)
|
||||
return `<${parseInt(result[1]) - startTime},${result[2]}>`
|
||||
return `<${parseInt(result![1]) - startTime},${result![2]}>`
|
||||
})
|
||||
const wordArr = words.split(this.rxps.wordTime)
|
||||
const newWords = times.map((time, index) => `${time}${wordArr[index]}`).join('')
|
||||
@@ -1,10 +1,11 @@
|
||||
import { sizeFormate, formatPlayTime } from '../index.js'
|
||||
import { createHttpFetch } from './utils/index.js'
|
||||
import { formatSingerName } from '../utils.js'
|
||||
import { sizeFormate, formatPlayTime } from '../index.ts'
|
||||
import { createHttpFetch } from './utils/index.ts'
|
||||
import { formatSingerName } from '../utils.ts'
|
||||
import type { SongInfo, SongType, QualityInfo, Quality } from '../types.ts'
|
||||
|
||||
const createGetMusicInfosTask = (ids) => {
|
||||
const createGetMusicInfosTask = (ids: Array<string | undefined>) => {
|
||||
let list = ids
|
||||
let tasks = []
|
||||
const tasks: Array<Array<string | undefined>> = []
|
||||
while (list.length) {
|
||||
tasks.push(list.slice(0, 100))
|
||||
if (list.length < 100) break
|
||||
@@ -19,15 +20,15 @@ const createGetMusicInfosTask = (ids) => {
|
||||
}).then(data => data.resource)))
|
||||
}
|
||||
|
||||
export const filterMusicInfoList = (rawList) => {
|
||||
export const filterMusicInfoList = (rawList: any[]): SongInfo[] => {
|
||||
// console.log(rawList)
|
||||
let ids = new Set()
|
||||
const list = []
|
||||
const list: any[] = []
|
||||
rawList.forEach(item => {
|
||||
if (!item.songId || ids.has(item.songId)) return
|
||||
ids.add(item.songId)
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: SongType[] = []
|
||||
const _types: Partial<Record<Quality, QualityInfo>> = {}
|
||||
item.newRateFormats?.forEach(type => {
|
||||
let size
|
||||
switch (type.formatType) {
|
||||
@@ -90,12 +91,12 @@ export const filterMusicInfoList = (rawList) => {
|
||||
export const filterMusicInfoListV5 = (rawList) => {
|
||||
// console.log(rawList)
|
||||
let ids = new Set()
|
||||
const list = []
|
||||
const list: any[] = []
|
||||
rawList.forEach(item => {
|
||||
if (!item.songId || ids.has(item.songId)) return
|
||||
ids.add(item.songId)
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: SongType[] = []
|
||||
const _types: Partial<Record<Quality, QualityInfo>> = {}
|
||||
item.audioFormats?.forEach(type => {
|
||||
let size
|
||||
switch (type.formatType) {
|
||||
@@ -153,10 +154,10 @@ export const filterMusicInfoListV5 = (rawList) => {
|
||||
return list
|
||||
}
|
||||
|
||||
export const getMusicInfo = async(copyrightId) => {
|
||||
export const getMusicInfo = async(copyrightId?: string): Promise<SongInfo | undefined> => {
|
||||
return getMusicInfos([copyrightId]).then(data => data[0])
|
||||
}
|
||||
|
||||
export const getMusicInfos = async(copyrightIds) => {
|
||||
export const getMusicInfos = async(copyrightIds: Array<string | undefined>): Promise<SongInfo[]> => {
|
||||
return filterMusicInfoList((await createGetMusicInfosTask(copyrightIds)).flat())
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { sizeFormate, formatPlayTime } from '../index.js'
|
||||
import { toMD5, formatSingerName } from '../utils.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { sizeFormate, formatPlayTime } from '../index.ts'
|
||||
import { toMD5, formatSingerName } from '../utils.ts'
|
||||
import type { SongType, QualityInfo, Quality } from '../types.ts'
|
||||
|
||||
export const createSignature = (time, str) => {
|
||||
export const createSignature = (time: string, str: string): { sign: string, deviceId: string } => {
|
||||
const deviceId = '963B7AA0D21511ED807EE5846EC87D20'
|
||||
const signatureMd5 = '6cdc72a439cef99a3418d2a78aa28c73'
|
||||
const sign = toMD5(`${str}${signatureMd5}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${time}`)
|
||||
@@ -126,7 +127,7 @@ export default {
|
||||
},
|
||||
filterData(rawData) {
|
||||
// console.log(rawData)
|
||||
const list = []
|
||||
const list: any[] = []
|
||||
const ids = new Set()
|
||||
|
||||
rawData.forEach(item => {
|
||||
@@ -134,8 +135,8 @@ export default {
|
||||
if (!data.songId || !data.copyrightId || ids.has(data.copyrightId)) return
|
||||
ids.add(data.copyrightId)
|
||||
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: SongType[] = []
|
||||
const _types: Partial<Record<Quality, QualityInfo>> = {}
|
||||
data.audioFormats && data.audioFormats.forEach(type => {
|
||||
let size
|
||||
switch (type.formatType) {
|
||||
@@ -1,5 +1,5 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import getSongId from './songId.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import getSongId from './songId.ts'
|
||||
|
||||
export default {
|
||||
async getPicUrl(songId, tryNum = 0) {
|
||||
@@ -11,7 +11,7 @@ export default {
|
||||
requestObj.promise.then(({ body }) => {
|
||||
if (body.returnCode !== '000000') {
|
||||
if (tryNum > 5) return Promise.reject(new Error('图片获取失败'))
|
||||
let tryRequestObj = this.getPic(songId, ++tryNum)
|
||||
let tryRequestObj = (this as any).getPic(songId, ++tryNum)
|
||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
// import { httpFetch } from '../request.js'
|
||||
import { getMusicInfo } from './musicInfo.js'
|
||||
import { getMusicInfo } from './musicInfo.ts'
|
||||
import type { SongInfo } from '../types.ts'
|
||||
|
||||
const getSongId = async(mInfo) => {
|
||||
const getSongId = async(mInfo: SongInfo): Promise<string | undefined> => {
|
||||
if (mInfo.songmid != mInfo.copyrightId) return mInfo.songmid
|
||||
const musicInfo = await getMusicInfo(mInfo.copyrightId)
|
||||
return musicInfo.songmid
|
||||
return musicInfo!.songmid
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { formatPlayCount } from '../index.js'
|
||||
import { filterMusicInfoListV5 } from './musicInfo.js'
|
||||
import { createSignature } from './musicSearch.js'
|
||||
import { createHttpFetch } from './utils/index.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { formatPlayCount } from '../index.ts'
|
||||
import { filterMusicInfoListV5 } from './musicInfo.ts'
|
||||
import { createSignature } from './musicSearch.ts'
|
||||
import { createHttpFetch } from './utils/index.ts'
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
|
||||
// const tagData = { code: '000000', info: 'SUCCESS', columnInfo: { columnTitle: '分类', columnId: '15244430', columnPid: '15031270', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 6, columnStatus: 1, columnCreateTime: '2016-11-10 10:53:05.077', columntype: 2011, contents: [{ contentId: '18464615', relationType: 2011, objectInfo: { columnTitle: '热门', columnId: '18464615', columnPid: '15244430', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 8, columnStatus: 1, columnCreateTime: '2017-02-20 16:09:13.400', columntype: 2011, contents: [{ contentId: '1000001672', relationType: 4034, objectInfo: { tagId: '1000001672', tagName: '流行', resourceType: '2034' }, relationSort: 9 }, { contentId: '1003449727', relationType: 4034, objectInfo: { tagId: '1003449727', tagName: '厂牌', resourceType: '2034' }, relationSort: 8 }, { contentId: '1000001795', relationType: 4034, objectInfo: { tagId: '1000001795', tagName: '伤感', resourceType: '2034' }, relationSort: 7 }, { contentId: '1001076080', relationType: 4034, objectInfo: { tagId: '1001076080', tagName: '电影', resourceType: '2034' }, relationSort: 6 }, { contentId: '1000001675', relationType: 4034, objectInfo: { tagId: '1000001675', tagName: '中国风', resourceType: '2034' }, relationSort: 5 }, { contentId: '1000001635', relationType: 4034, objectInfo: { tagId: '1000001635', tagName: '经典老歌', resourceType: '2034' }, relationSort: 4 }, { contentId: '1000001831', relationType: 4034, objectInfo: { tagId: '1000001831', tagName: '翻唱', resourceType: '2034' }, relationSort: 3 }, { contentId: '1000001762', relationType: 4034, objectInfo: { tagId: '1000001762', tagName: '国语', resourceType: '2034' }, relationSort: 1 }], dataVersion: '1620410266029', customizedPicUrls: [] }, relationSort: 6 }, { contentId: '15244503', relationType: 2011, objectInfo: { columnTitle: '主题', columnId: '15244503', columnPid: '15244430', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 23, columnStatus: 1, columnCreateTime: '2016-11-10 10:54:10.261', columntype: 2011, contents: [{ contentId: '1003449727', relationType: 4034, objectInfo: { tagId: '1003449727', tagName: '厂牌', resourceType: '2034' }, relationSort: 29 }, { contentId: '1001076080', relationType: 4034, objectInfo: { tagId: '1001076080', tagName: '电影', resourceType: '2034' }, relationSort: 28 }, { contentId: '1001076078', relationType: 4034, objectInfo: { tagId: '1001076078', tagName: '电视剧', resourceType: '2034' }, relationSort: 27 }, { contentId: '1001076083', relationType: 4034, objectInfo: { tagId: '1001076083', tagName: '综艺', resourceType: '2034' }, relationSort: 26 }, { contentId: '1000001827', relationType: 4034, objectInfo: { tagId: '1000001827', tagName: 'KTV', resourceType: '2034' }, relationSort: 23 }, { contentId: '1000001698', relationType: 4034, objectInfo: { tagId: '1000001698', tagName: '爱情', resourceType: '2034' }, relationSort: 22 }, { contentId: '1000001635', relationType: 4034, objectInfo: { tagId: '1000001635', tagName: '经典老歌', resourceType: '2034' }, relationSort: 21 }, { contentId: '1001076096', relationType: 4034, objectInfo: { tagId: '1001076096', tagName: '网络热歌', resourceType: '2034' }, relationSort: 20 }, { contentId: '1000001780', relationType: 4034, objectInfo: { tagId: '1000001780', tagName: '儿童歌曲', resourceType: '2034' }, relationSort: 19 }, { contentId: '1000587702', relationType: 4034, objectInfo: { tagId: '1000587702', tagName: '广场舞', resourceType: '2034' }, relationSort: 18 }, { contentId: '1000587717', relationType: 4034, objectInfo: { tagId: '1000587717', tagName: '70后', resourceType: '2034' }, relationSort: 17 }, { contentId: '1000587718', relationType: 4034, objectInfo: { tagId: '1000587718', t
Line truncated
|
||||
|
||||
export default {
|
||||
_requestObj_tags: null,
|
||||
_requestObj_list: null,
|
||||
_requestObj_tags: null as HttpRequestObject | null,
|
||||
_requestObj_list: null as HttpRequestObject | null,
|
||||
limit_list: 30,
|
||||
limit_song: 50,
|
||||
successCode: '000000',
|
||||
@@ -200,7 +201,7 @@ export default {
|
||||
// source: 'mg',
|
||||
// }
|
||||
// })
|
||||
return this._requestObj_list.promise.then(({ body }) => {
|
||||
return this._requestObj_list!.promise.then(({ body }) => {
|
||||
// console.log(body)
|
||||
// if (body.retCode !== '000000') return this.getList(sortId, tagId, page, ++tryNum)
|
||||
if (body.code !== '000000') return this.getList(sortId, tagId, page, ++tryNum)
|
||||
@@ -214,7 +215,7 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
filterList2(listData, list = [], ids = new Set()) {
|
||||
filterList2(listData, list: any[] = [], ids = new Set()) {
|
||||
for (const item of listData) {
|
||||
if (item.contents) this.filterList2(item.contents, list, ids)
|
||||
else if (item.resType == '2021' && !ids.has(item.resId)) {
|
||||
@@ -255,7 +256,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.tagsUrl, { headers: this.defaultHeaders })
|
||||
return this._requestObj_tags.promise.then(({ body }) => {
|
||||
return this._requestObj_tags!.promise.then(({ body }) => {
|
||||
if (body.code !== this.successCode) return this.getTag(++tryNum)
|
||||
// console.log(body)
|
||||
return this.filterTagInfo(body.data)
|
||||
@@ -314,7 +315,7 @@ export default {
|
||||
},
|
||||
|
||||
filterSongListResult(raw) {
|
||||
const list = []
|
||||
const list: any[] = []
|
||||
raw.forEach(item => {
|
||||
if (!item.id) return
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createHttpFetch } from './utils/index.js'
|
||||
import { createHttpFetch } from './utils/index.ts'
|
||||
|
||||
export default {
|
||||
requestObj: null,
|
||||
requestObj: null as any,
|
||||
cancelTipSearch() {
|
||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||
},
|
||||
@@ -1,4 +1,5 @@
|
||||
import { httpFetch } from '../../request.js'
|
||||
import { httpFetch } from '../../request.ts'
|
||||
import type { HttpOptions } from '../../types.ts'
|
||||
|
||||
/**
|
||||
* 创建一个适用于MG的Http请求
|
||||
@@ -6,7 +7,7 @@ import { httpFetch } from '../../request.js'
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
*/
|
||||
export const createHttpFetch = async(url, options, retryNum = 0) => {
|
||||
export const createHttpFetch = async(url: string, options?: HttpOptions, retryNum = 0): Promise<any> => {
|
||||
if (retryNum > 2) throw new Error('try max num')
|
||||
let result
|
||||
try {
|
||||
@@ -16,7 +16,7 @@ const keyArr = [
|
||||
]
|
||||
|
||||
|
||||
const teaDecrypt = (data, key) => {
|
||||
const teaDecrypt = (data: bigint[], key: bigint[]): bigint[] => {
|
||||
const length = data.length
|
||||
const lengthBitint = BigInt(length)
|
||||
if (length >= 1) {
|
||||
@@ -31,14 +31,14 @@ const teaDecrypt = (data, key) => {
|
||||
while (true) {
|
||||
j6--
|
||||
if (j6 > 0n) {
|
||||
let j7 = data[(j6 - 1n)]
|
||||
let i = j6
|
||||
j2 = toLong(data[i] - (toLong(toLong(j2 ^ j4) + toLong(j7 ^ key[toLong(toLong(3n & j6) ^ j5)])) ^ toLong(toLong(toLong(j7 >> 5n) ^ toLong(j2 << 2n)) + toLong(toLong(j2 >> 3n) ^ toLong(j7 << 4n)))))
|
||||
let j7 = data[(j6 - 1n) as unknown as number]
|
||||
let i = j6 as unknown as number
|
||||
j2 = toLong(data[i] - (toLong(toLong(j2 ^ j4) + toLong(j7 ^ key[toLong(toLong(3n & j6) ^ j5) as unknown as number])) ^ toLong(toLong(toLong(j7 >> 5n) ^ toLong(j2 << 2n)) + toLong(toLong(j2 >> 3n) ^ toLong(j7 << 4n)))))
|
||||
data[i] = j2
|
||||
} else break
|
||||
}
|
||||
let j8 = data[lengthBitint - 1n]
|
||||
j2 = toLong(data[0n] - toLong(toLong(toLong(key[toLong(toLong(j6 & 3n) ^ j5)] ^ j8) + toLong(j2 ^ j4)) ^ toLong(toLong(toLong(j8 >> 5n) ^ toLong(j2 << 2n)) + toLong(toLong(j2 >> 3n) ^ toLong(j8 << 4n)))))
|
||||
let j8 = data[lengthBitint - 1n as unknown as number]
|
||||
j2 = toLong(data[0n as unknown as number] - toLong(toLong(toLong(key[toLong(toLong(j6 & 3n) ^ j5) as unknown as number] ^ j8) + toLong(j2 ^ j4)) ^ toLong(toLong(toLong(j8 >> 5n) ^ toLong(j2 << 2n)) + toLong(toLong(j2 >> 3n) ^ toLong(j8 << 4n)))))
|
||||
data[0] = j2
|
||||
j3 = toLong(j4 - DELTA)
|
||||
}
|
||||
@@ -46,26 +46,26 @@ const teaDecrypt = (data, key) => {
|
||||
return data
|
||||
}
|
||||
|
||||
const longArrToString = (data) => {
|
||||
const arrayList = []
|
||||
const longArrToString = (data: bigint[]): string => {
|
||||
const arrayList: string[] = []
|
||||
for (const j of data) arrayList.push(longToBytes(j).toString('utf16le'))
|
||||
return arrayList.join('')
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/29132118
|
||||
const longToBytes = (l) => {
|
||||
const longToBytes = (l: bigint): Buffer => {
|
||||
const result = Buffer.alloc(8)
|
||||
for (let i = 0; i < 8; i++) {
|
||||
result[i] = parseInt(l & 0xFFn)
|
||||
result[i] = parseInt((l & 0xFFn) as unknown as string)
|
||||
l >>= 8n
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
const toBigintArray = (data) => {
|
||||
const toBigintArray = (data: string): bigint[] => {
|
||||
const length = Math.floor(data.length / 16)
|
||||
const jArr = Array(length)
|
||||
const jArr: bigint[] = Array(length)
|
||||
for (let i = 0; i < length; i++) {
|
||||
jArr[i] = toLong(data.substring(i * 16, (i * 16) + 16))
|
||||
}
|
||||
@@ -75,14 +75,14 @@ const toBigintArray = (data) => {
|
||||
// https://github.com/lyswhut/lx-music-desktop/issues/445#issuecomment-1139338682
|
||||
const MAX = 9223372036854775807n
|
||||
const MIN = -9223372036854775808n
|
||||
const toLong = str => {
|
||||
const toLong = (str: string | bigint): bigint => {
|
||||
const num = typeof str == 'string' ? BigInt('0x' + str) : str
|
||||
if (num > MAX) return toLong(num - (1n << 64n))
|
||||
else if (num < MIN) return toLong(num + (1n << 64n))
|
||||
return num
|
||||
}
|
||||
|
||||
export const decrypt = (data) => {
|
||||
export const decrypt = (data: string | null): string | null => {
|
||||
// console.log(data.length)
|
||||
// -3551594764563790630
|
||||
// console.log(toLongArrayFromArr(Buffer.from(key)))
|
||||
Reference in new issue
Block a user