refactor(sdk): 审计 P2 卫生项清理——请求层收敛与死代码清除
- 删除旧 sdk/request.ts,全部 import 收敛到 sdk/common/request.ts(85 文件) - 注释死代码 630+ 行、裸 console.log 吞错 6 处、未使用符号 26 处清零 - bili 状态校验去重;utils DNS 预解析失败日志改 warn 带上下文 - CODE-AUDIT.md:第四节 P2 清理记录 + 第八节线索逐条复核结论(kw/kg/tx/wy parse 骨架相似实质各异,不抽公共层)
This commit is contained in:
1 parent
ecca1b8458
commit
8c02fb5c15
85 files changed
+112
-839
No files matched your search
+1
-1
@@ -3,7 +3,7 @@
|
||||
// 曲目:music.musichallAlbum.AlbumSongList GetAlbumSongList 按 100 一批翻页(上游 fetchAlbumDetail 的曲目段)
|
||||
// 详情:GetAlbumInfo 详情接口已停用:专辑名取自曲目自带的 album 信息,作者由曲目歌手去重合成,封面走平台固定 URL 规则
|
||||
// 链接解析:albumDetail/<mid>、album/<mid>、albummid=<mid>(上游 ParseAlbum)
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import { filterMusicInfoItem } from './singer.ts'
|
||||
import { createMusicuFetch } from './utils/index.ts'
|
||||
|
||||
|
||||
+1
-3
@@ -1,5 +1,5 @@
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import { dateFormat2 } from '../index.ts'
|
||||
import getMusicInfo from './musicInfo.ts'
|
||||
|
||||
@@ -114,7 +114,6 @@ export default {
|
||||
})
|
||||
const { body, statusCode } = await _requestObj.promise
|
||||
if (statusCode != 200 || body.code !== 0) throw new Error('获取评论失败')
|
||||
// console.log(body, statusCode)
|
||||
const comment = body.comment
|
||||
return {
|
||||
source: 'tx',
|
||||
@@ -183,7 +182,6 @@ export default {
|
||||
},
|
||||
})
|
||||
const { body, statusCode } = await _requestObj2.promise
|
||||
// console.log('body', body)
|
||||
if (statusCode != 200 || body.code !== 0 || body.req.code !== 0) throw new Error('获取热门评论失败')
|
||||
const comment = body.req.data.CommentList
|
||||
return {
|
||||
|
||||
+1
-3
@@ -1,5 +1,5 @@
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
|
||||
export default {
|
||||
_requestObj: null as HttpRequestObject | null,
|
||||
@@ -44,9 +44,7 @@ export default {
|
||||
},
|
||||
})
|
||||
const { body, statusCode } = await _requestObj.promise
|
||||
// console.log(body)
|
||||
if (statusCode != 200 || body.code !== 0) throw new Error('获取热搜词失败')
|
||||
// console.log(body)
|
||||
return { source: 'tx', list: this.filterList(body.hotkey.data.vec_hotkey) }
|
||||
},
|
||||
filterList(rawList) {
|
||||
|
||||
+3
-23
@@ -1,5 +1,5 @@
|
||||
import type { HttpRequestObject, SongInfo, SongType, Quality, QualityInfo } from '../types.ts'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import type { HttpRequestObject, SongType, Quality, QualityInfo } from '../types.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import { formatPlayTime, sizeFormate } from '../index.ts'
|
||||
import { formatSingerName } from '../utils.ts'
|
||||
|
||||
@@ -65,7 +65,6 @@ export default {
|
||||
},
|
||||
],
|
||||
listDetailRequest(id, period, limit) {
|
||||
// console.log(id, period, limit)
|
||||
return httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
@@ -107,7 +106,6 @@ export default {
|
||||
return requestDataObj.promise
|
||||
},
|
||||
filterData(rawList) {
|
||||
// console.log(rawList)
|
||||
return rawList.map(item => {
|
||||
let types: SongType[] = []
|
||||
let _types: Partial<Record<Quality, QualityInfo>> = {}
|
||||
@@ -180,7 +178,6 @@ export default {
|
||||
})
|
||||
},
|
||||
filterBoardsData(rawList) {
|
||||
// console.log(rawList)
|
||||
let list: any[] = []
|
||||
for (const board of rawList) {
|
||||
// 排除 MV榜
|
||||
@@ -198,24 +195,7 @@ export default {
|
||||
}
|
||||
return list
|
||||
},
|
||||
async getBoards(retryNum = 0) {
|
||||
// if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||
// let response
|
||||
// try {
|
||||
// response = await this.getBoardsData()
|
||||
// } catch (error) {
|
||||
// return this.getBoards(retryNum)
|
||||
// }
|
||||
// // console.log(response.body)
|
||||
// if (response.statusCode !== 200 || response.body.code !== 0) return this.getBoards(retryNum)
|
||||
// const list = this.filterBoardsData(response.body.data.topList)
|
||||
// console.log(list)
|
||||
// console.log(JSON.stringify(list))
|
||||
// this.list = list
|
||||
// return {
|
||||
// list,
|
||||
// source: 'tx',
|
||||
// }
|
||||
async getBoards() {
|
||||
this.list = boardList
|
||||
return {
|
||||
list: boardList,
|
||||
|
||||
+1
-35
@@ -1,5 +1,4 @@
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import getMusicInfo from './musicInfo.ts'
|
||||
import { decodeQrc } from './qrcDecode.ts'
|
||||
|
||||
@@ -111,8 +110,6 @@ const parseTools = {
|
||||
return parseInt(m) * 3600000 + parseInt(s) * 1000 + parseInt(ms)
|
||||
},
|
||||
fixRlrcTimeTag(rlrc, lrc) {
|
||||
// console.log(lrc)
|
||||
// console.log(rlrc)
|
||||
const rlrcLines = rlrc.split('\n')
|
||||
let lrcLines = lrc.split('\n')
|
||||
// let temp: string[] = []
|
||||
@@ -141,8 +138,6 @@ const parseTools = {
|
||||
return newLrc.join('\n')
|
||||
},
|
||||
fixTlrcTimeTag(tlrc, lrc) {
|
||||
// console.log(lrc)
|
||||
// console.log(tlrc)
|
||||
const tlrcLines = tlrc.split('\n')
|
||||
let lrcLines = lrc.split('\n')
|
||||
// let temp: string[] = []
|
||||
@@ -185,14 +180,9 @@ const parseTools = {
|
||||
let { lyric, yrc } = this.parseLyric(this.removeTag(lrc))
|
||||
info.lyric = lyric
|
||||
info.yrc = yrc
|
||||
// console.log(lyric)
|
||||
// console.log(yrc)
|
||||
}
|
||||
if (rlrc) info.rlyric = this.fixRlrcTimeTag(this.parseRlyric(this.removeTag(rlrc)), info.lyric)
|
||||
if (tlrc) info.tlyric = this.fixTlrcTimeTag(tlrc, info.lyric)
|
||||
// console.log(info.lyric)
|
||||
// console.log(info.tlyric)
|
||||
// console.log(info.rlyric)
|
||||
|
||||
return info
|
||||
},
|
||||
@@ -218,9 +208,6 @@ export default {
|
||||
// return {
|
||||
|
||||
// }
|
||||
// console.log(lyric)
|
||||
// console.log(tlyric)
|
||||
// console.log(rlyric)
|
||||
return parseTools.parse(lyric, tlyric, rlyric)
|
||||
},
|
||||
getLyric(mInfo, retryNum = 0) {
|
||||
@@ -266,7 +253,6 @@ export default {
|
||||
},
|
||||
})
|
||||
return requestObj.promise.then(({ body }) => {
|
||||
// console.log(body)
|
||||
if (body.code != this.successCode || body.req.code != this.successCode) return this.getLyric(songId, ++retryNum)
|
||||
const data = body.req.data
|
||||
return this.parseLyric(data.lyric, data.trans, data.roma)
|
||||
@@ -276,23 +262,3 @@ export default {
|
||||
},
|
||||
}
|
||||
|
||||
// export default {
|
||||
// regexps: {
|
||||
// matchLrc: /.+"lyric":"([\w=+/]*)".+/,
|
||||
// },
|
||||
// getLyric(songmid) {
|
||||
// const requestObj = httpFetch(`https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?songmid=${songmid}&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&platform=yqq`, {
|
||||
// headers: {
|
||||
// Referer: 'https://y.qq.com/portal/player.html',
|
||||
// },
|
||||
// })
|
||||
// requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
// if (body.code != 0 || !body.lyric) return Promise.reject(new Error('Get lyric failed'))
|
||||
// return {
|
||||
// lyric: decodeName(b64DecodeUnicode(body.lyric)),
|
||||
// tlyric: decodeName(b64DecodeUnicode(body.trans)),
|
||||
// }
|
||||
// })
|
||||
// return requestObj
|
||||
// },
|
||||
// }
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
import type { HttpRequestObject, SongType, Quality, QualityInfo } from '../types.ts'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import type { SongType, Quality, QualityInfo } from '../types.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import { formatPlayTime, sizeFormate } from '../index.ts'
|
||||
|
||||
const getSinger = (singers) => {
|
||||
@@ -33,7 +33,6 @@ export default (songmid) => {
|
||||
},
|
||||
})
|
||||
return requestObj.promise.then(({ body }) => {
|
||||
// console.log(body)
|
||||
if (body.code != 0 || body.req.code != 0) return Promise.reject(new Error('获取歌曲信息失败'))
|
||||
const item = body.req.data.track_info
|
||||
if (!item.file?.media_mid) return null
|
||||
|
||||
@@ -61,26 +61,13 @@ export default {
|
||||
},
|
||||
})
|
||||
return searchRequest.then(({ body }) => {
|
||||
// console.log(body)
|
||||
if (!body || !body.req || body.code != this.successCode || body.req.code != this.successCode) {
|
||||
return this.musicSearch(str, page, limit, ++retryNum)
|
||||
}
|
||||
return body.req.data
|
||||
})
|
||||
},
|
||||
// randomInt(min, max) {
|
||||
// return Math.floor(Math.random() * (max - min + 1)) + min
|
||||
// },
|
||||
// getSearchId() {
|
||||
// const e = BigInt(this.randomInt(1, 20))
|
||||
// const t = e * 18014398509481984n
|
||||
// const n = BigInt(this.randomInt(0, 4194304)) * 4294967296n
|
||||
// const a = BigInt(Date.now())
|
||||
// const r = (a * 1000n) % (24n * 60n * 60n * 1000n)
|
||||
// return String(t + n + r)
|
||||
// },
|
||||
handleResult(rawList) {
|
||||
// console.log(rawList)
|
||||
if (!rawList || !Array.isArray(rawList)) return []
|
||||
const list: SongInfo[] = []
|
||||
rawList.forEach(item => {
|
||||
@@ -144,7 +131,6 @@ export default {
|
||||
typeUrl: {},
|
||||
})
|
||||
})
|
||||
// console.log(list)
|
||||
return list
|
||||
},
|
||||
search(str, page = 1, limit) {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
// https://i.y.qq.com/v8/playsong.html?songid=<数字 id>(先反查 songmid)
|
||||
// ...?songmid=<songmid>
|
||||
// 返回 Song(含 songmid);直链 url/type 为尽力附带,失败不影响元数据返回(与上游一致)。
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import { formatPlayTime, sizeFormate } from '../index.ts'
|
||||
import { formatSingerName } from '../utils.ts'
|
||||
import txApi from '../apis/tx.ts'
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// 搜索/分类复用现有 sdk/tx/songList.ts(handleParseId / getListId / getListDetail / getTag / getList)
|
||||
// 推荐:musicu.fcg playlist.HotRecommendServer/get_hot_recommend(上游 GetRecommendedPlaylists)
|
||||
// 链接解析:extractPlaylistId 为上游 extractQQPlaylistID 的 1:1 移植(含单测用例断言)
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import { formatPlayCount } from '../index.ts'
|
||||
import songList from './songList.ts'
|
||||
|
||||
|
||||
+1
-7
@@ -1,5 +1,5 @@
|
||||
import type { HttpRequestObject, SongType, Quality, QualityInfo } from '../types.ts'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../index.ts'
|
||||
import { formatSingerName } from '../utils.ts'
|
||||
|
||||
@@ -120,7 +120,6 @@ export default {
|
||||
this._requestObj_list = httpFetch(
|
||||
this.getListUrl(sortId, tagId, page),
|
||||
)
|
||||
// console.log(this.getListUrl(sortId, tagId, page))
|
||||
return this._requestObj_list!.promise.then(({ body }) => {
|
||||
if (body.code !== this.successCode) return this.getList(sortId, tagId, page, ++tryNum)
|
||||
return tagId ? this.filterList2(body.playlist.data, page) : this.filterList(body.playlist.data, page)
|
||||
@@ -148,7 +147,6 @@ export default {
|
||||
}
|
||||
},
|
||||
filterList2({ content }, page) {
|
||||
// console.log(content.v_item)
|
||||
return {
|
||||
list: content.v_item.map(({ basic }) => ({
|
||||
play_count: formatPlayCount(basic.play_cnt),
|
||||
@@ -173,7 +171,6 @@ export default {
|
||||
|
||||
const requestObj_listDetailLink = httpFetch(link)
|
||||
const { headers: { location }, statusCode } = await requestObj_listDetailLink.promise
|
||||
// console.log(headers)
|
||||
if (statusCode > 400) return this.handleParseId(link, ++retryNum)
|
||||
return location == null ? link : location
|
||||
},
|
||||
@@ -189,7 +186,6 @@ export default {
|
||||
if (!result) throw new Error('failed')
|
||||
}
|
||||
id = result[1]
|
||||
// console.log(id)
|
||||
}
|
||||
return id
|
||||
},
|
||||
@@ -225,7 +221,6 @@ export default {
|
||||
}
|
||||
},
|
||||
filterListDetail(rawList) {
|
||||
// console.log(rawList)
|
||||
return rawList.map(item => {
|
||||
let types: SongType[] = []
|
||||
let _types: Partial<Record<Quality, QualityInfo>> = {}
|
||||
@@ -300,7 +295,6 @@ export default {
|
||||
})
|
||||
.promise.then(({ body }) => {
|
||||
if (body.code != 0) return this.search(text, page, limit, ++retryNum)
|
||||
// console.log(body.data.list)
|
||||
return {
|
||||
list: body.data.list.map(item => {
|
||||
return {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// 2) fcg_get_profile_order_asset reqtype=3 → 收藏歌单
|
||||
// 3) fcg_get_profile_order_asset reqtype=1 → 「我喜欢的歌曲」虚拟歌单摘要(有歌才附上)
|
||||
// 说明:虚拟条目的 id 为 profile:favorites(与上游一致),歌曲需凭 cookie 走同一接口拉取
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { httpFetch } from '../common/request.ts'
|
||||
import { formatPlayCount } from '../index.ts'
|
||||
import { getCredentials } from '../auth/store.ts'
|
||||
import type { TxCredentials } from '../auth/store.ts'
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import type { HttpRequestObject } from '../../types.ts'
|
||||
|
||||
import { httpFetch } from '../../request.ts'
|
||||
import { httpFetch } from '../../common/request.ts'
|
||||
import { zzcSign } from './crypto.ts'
|
||||
|
||||
export const signRequest = async(data) => {
|
||||
// console.log(data)
|
||||
const sign = await zzcSign(JSON.stringify(data))
|
||||
// console.log('sign', sign)
|
||||
return httpFetch(`https://u.y.qq.com/cgi-bin/musics.fcg?sign=${sign}`, {
|
||||
method: 'post',
|
||||
headers: {
|
||||
@@ -36,7 +32,7 @@ export const createMusicuFetch = async(data, retryNum = 0) => {
|
||||
},
|
||||
}).promise
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
console.warn(`[tx] musicu 请求失败将重试(${retryNum + 1}/3): ${(err as Error).message}`)
|
||||
return createMusicuFetch(data, ++retryNum)
|
||||
}
|
||||
if (result.statusCode !== 200 || result.body.code != 0) return createMusicuFetch(data, ++retryNum)
|
||||
|
||||
Reference in new issue
Block a user