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:
snowy-yang committed 2026-10-03 20:48:54 +08:00
1 parent ecca1b8458
commit 8c02fb5c15
85 files changed
+112 -839

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
// 搜索:cloudsearch pc type=10(eapi 通道,与现有 songList.search 同一通路)
// 详情/曲目:weapi/v1/album/<id>(匿名可用;登录 cookie 可选)
// 链接解析:#/album?id= / /album?id= / /album/<id>(上游 parseNeteaseLink)
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { weapi } from './utils/crypto.ts'
import { formatPlayTime, sizeFormate } from '../index.ts'
import { formatSingerName } from '../utils.ts'
+1 -2
View File
@@ -1,4 +1,4 @@
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { weapi } from './utils/crypto.ts'
import { dateFormat2 } from '../index.ts'
import type { HttpRequestObject } from '../types.ts'
@@ -149,7 +149,6 @@ export default {
}),
})
const { body, statusCode } = await _requestObj.promise
// console.log(body)
if (statusCode != 200 || body.code !== 200) throw new Error('获取评论失败')
cursorTools.setCursor(songmid, body.data.cursor, cursorInfo.orderType, cursorInfo.offset, page)
return { source: 'wy', comments: this.filterComment(body.data.comments), total: body.data.totalCount, page, limit, maxPage: Math.ceil(body.data.totalCount / limit) || 1 }
+3 -24
View File
@@ -1,5 +1,5 @@
import { weapi } from './utils/crypto.ts'
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import musicDetailApi from './musicDetail.ts'
import type { HttpRequestObject } from '../types.ts'
@@ -129,7 +129,6 @@ export default {
},
filterBoardsData(rawList) {
// console.log(rawList)
let list: any[] = []
for (const board of rawList) {
// 排除 MV榜
@@ -142,24 +141,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 !== 200) return this.getBoards(retryNum)
// const list = this.filterBoardsData(response.body.list)
// console.log(list)
// console.log(JSON.stringify(list))
// this.list = list
// return {
// list,
// source: 'wy',
// }
async getBoards() {
this.list = topList
return {
list: topList,
@@ -168,7 +150,6 @@ export default {
},
async getList(bangid, page, retryNum = 0) {
if (++retryNum > 6) return Promise.reject(new Error('try max num'))
// console.log(bangid)
let resp
try {
resp = await this.getData(bangid)
@@ -180,19 +161,17 @@ export default {
}
}
if (resp.statusCode !== 200 || resp.body.code !== 200) return this.getList(bangid, page, retryNum)
// console.log(resp.body)
let musicDetail
try {
musicDetail = await (musicDetailApi as any).getList(resp.body.playlist.trackIds.map(trackId => trackId.id))
} catch (err: any) {
console.log(err)
console.warn(`[wy] 榜单歌曲详情获取失败将重试(${retryNum + 1}): ${err.message}`)
if (err.message == 'try max num') {
throw err
} else {
return this.getList(bangid, page, retryNum)
}
}
// console.log(musicDetail)
return {
total: musicDetail.list.length,
list: musicDetail.list,
+2 -75
View File
@@ -1,39 +1,6 @@
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { eapi } from './utils/crypto.ts'
import type { LyricInfo, HttpRequestObject } from '../types.ts'
// import { decodeName } from '../...ts'
// const parseLyric = (str, lrc) => {
// if (!str) return ''
// str = str.replace(/\r/g, '')
// let yrc = str.replace(/\[((\d+),\d+)\].*/g, str => {
// let result = str.match(/\[((\d+),\d+)\].*/)
// let time = parseInt(result[2])
// let ms = time % 1000
// time /= 1000
// let m = parseInt(time / 60).toString().padStart(2, '0')
// time %= 60
// let s = parseInt(time).toString().padStart(2, '0')
// time = `${m}:${s}.${ms}`
// str = str.replace(result[1], time)
// let startTime = 0
// str = str.replace(/\(0,1\) /g, ' ').replace(/\(\d+,\d+\)/g, time => {
// const [start, end] = time.replace(/^\((\d+,\d+)\)$/, '$1').split(',')
// time = `<${parseInt(startTime + parseInt(start))},${end}>`
// startTime = parseInt(startTime + parseInt(end))
// return time
// })
// return str
// })
// yrc = decodeName(yrc)
// return yrc.trim()
// }
import type { HttpRequestObject } from '../types.ts'
const eapiRequest = (url: string, data: object) => {
return httpFetch('https://interface3.music.163.com/eapi/song/lyric/v1', {
@@ -41,18 +8,9 @@ const eapiRequest = (url: string, data: object) => {
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
origin: 'https://music.163.com',
// cookie: 'os=pc; deviceId=A9C064BB4584D038B1565B58CB05F95290998EE8B025AA2D07AE; osver=Microsoft-Windows-10-Home-China-build-19043-64bit; appver=2.5.2.197409; channel=netease; MUSIC_A=37a11f2eb9de9930cad479b2ad495b0e4c982367fb6f909d9a3f18f876c6b49faddb3081250c4980dd7e19d4bd9bf384e004602712cf2b2b8efaafaab164268a00b47359f85f22705cc95cb6180f3aee40f5be1ebf3148d888aa2d90636647d0c3061cd18d77b7a0; __csrf=05b50d54082694f945d7de75c210ef94; mode=Z7M-KP5(7)GZ; NMTID=00OZLp2VVgq9QdwokUgq3XNfOddQyIAAAF_6i8eJg; ntes_kaola_ad=1',
},
form: eapi(url, data),
})
// requestObj.promise = requestObj.promise.then(({ body }) => {
// // console.log(raw)
// console.log(body)
// // console.log(eapiDecrypt(raw))
// // return eapiDecrypt(raw)
// return body
// })
// return requestObj
}
const parseTools = {
@@ -218,35 +176,6 @@ const parseTools = {
}
// https://github.com/Binaryify/NeteaseCloudMusicApi/pull/1523/files
// export default songmid => {
// const requestObj = httpFetch('https://music.163.com/api/linux/forward', {
// method: 'post',
// 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
// form: linuxapi({
// method: 'POST',
// url: 'https://music.163.com/api/song/lyric?_nmclfl=1',
// params: {
// id: songmid,
// tv: -1,
// lv: -1,
// rv: -1,
// kv: -1,
// },
// }),
// })
// requestObj.promise = requestObj.promise.then(({ body }) => {
// if (body.code !== 200 || !body?.lrc?.lyric) return Promise.reject(new Error('Get lyric failed'))
// // console.log(body)
// return {
// lyric: body.lrc.lyric,
// tlyric: body.tlyric?.lyric ?? '',
// rlyric: body.romalrc?.lyric ?? '',
// // yrc: parseLyric(body.klyric.lyric),
// }
// })
// return requestObj
// }
// 参考社区通用的歌词时间标签修正思路
const fixTimeLabel = (lrc: string, tlrc?: string, romalrc?: string) => {
@@ -277,11 +206,9 @@ export default (songmid: string): HttpRequestObject => {
yrv: 0,
})
requestObj.promise = requestObj.promise.then(({ body }) => {
// console.log(body)
if (body.code !== 200 || !body?.lrc?.lyric) return Promise.reject(new Error('Get lyric failed'))
const fixTimeLabelLrc = fixTimeLabel(body.lrc.lyric, body.tlyric?.lyric, body.romalrc?.lyric)
const info = parseTools.parse(body.yrc?.lyric, body.ytlrc?.lyric, body.yromalrc?.lyric, fixTimeLabelLrc.lrc, fixTimeLabelLrc.tlrc, fixTimeLabelLrc.romalrc)
// console.log(info)
if (!info.lyric) return Promise.reject(new Error('Get lyric failed'))
return info
}) as any
+1 -4
View File
@@ -1,4 +1,4 @@
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { weapi } from './utils/crypto.ts'
import { formatPlayTime, sizeFormate } from '../index.ts'
// https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/module/song_detail.js
@@ -12,7 +12,6 @@ export default {
return arr.join('、')
},
filterList({ songs, privileges }) {
// console.log(songs, privileges)
const list: any[] = []
songs.forEach((item, index) => {
const types: Array<{ type: string, size: string | null }> = []
@@ -87,7 +86,6 @@ export default {
})
}
})
// console.log(list)
return list
},
async getList(ids = [], retryNum = 0) {
@@ -106,7 +104,6 @@ export default {
})
const { body, statusCode } = await requestObj.promise
if (statusCode != 200 || body.code !== 200) throw new Error('获取歌曲详情失败')
// console.log(body)
return { source: 'wy', list: this.filterList(body) }
},
}
+1 -2
View File
@@ -1,5 +1,5 @@
// https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/module/song_detail.js
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { weapi } from './utils/crypto.ts'
import type { RequestObj } from '../types.ts'
@@ -17,7 +17,6 @@ export default (songmid: string): RequestObj<any> => {
}),
})
requestObj.promise = requestObj.promise.then(({ body }) => {
// console.log(body)
if (body.code !== 200 || !body.songs.length) return Promise.reject(new Error('获取歌曲信息失败'))
return body.songs[0]
})
+1 -4
View File
@@ -1,4 +1,4 @@
// import { httpFetch } from '../request.ts'
// import { httpFetch } from '../common/request.ts'
// import { weapi } from './utils/crypto.ts'
import { sizeFormate, formatPlayTime } from '../index.ts'
// import musicDetailApi from './musicDetail.ts'
@@ -36,7 +36,6 @@ export default {
return arr.join('、')
},
handleResult(rawList) {
// console.log(rawList)
if (!rawList) return []
return rawList.map(item => {
item = item.baseInfo.simpleSongData
@@ -95,10 +94,8 @@ export default {
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
if (limit == null) limit = this.limit
return this.musicSearch(str, page, limit).then(result => {
// console.log(result)
if (!result || result.code !== 200) return this.search(str, page, limit, retryNum)
let list = this.handleResult(result.data.resources || [])
// console.log(list)
if (list == null) return this.search(str, page, limit, retryNum)
+1 -1
View File
@@ -6,7 +6,7 @@
// 裸数字 id 也接受(补充便利;上游仅接受链接)
// 直链 url/type 为尽力附带,失败不影响元数据返回(与上游一致);
// 歌单/专辑链接抛清晰错误,提示使用对应 parsePlaylist/parseAlbum。
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { weapi } from './utils/crypto.ts'
import { getWyCookie } from '../auth/store.ts'
import wyApi from '../apis/wy.ts'
+1 -1
View File
@@ -3,7 +3,7 @@
// 推荐:weapi/personalized/playlist(上游 GetRecommendedPlaylists,匿名可用)
// 详情/曲目:复用 songList.getListDetail(linuxapi forward),按 page/limit 切片
// 链接解析:#/playlist?id= / /playlist?id= / /playlist/<id>/<n>/... / 裸数字 id(上游 parseNeteaseLink)
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { weapi } from './utils/crypto.ts'
import { formatPlayCount } from '../index.ts'
import { getWyCookie } from '../auth/store.ts'
+2 -12
View File
@@ -4,7 +4,7 @@
// https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/module/playlist_detail.js
import { weapi, linuxapi } from './utils/crypto.ts'
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../index.ts'
import musicDetailApi from './musicDetail.ts'
import { eapiRequest } from './utils/index.ts'
@@ -39,7 +39,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)
const url = location == null ? link : location
return this.regExps.listDetailLink.test(url)
@@ -62,7 +61,6 @@ export default {
} else {
id = await this.handleParseId(id)
}
// console.log(id)
}
return { id, cookie }
},
@@ -92,7 +90,6 @@ export default {
if (statusCode !== 200 || body.code !== this.successCode) return this.getListDetail(id, page, ++tryNum)
let limit = 1000
let rangeStart = (page - 1) * limit
// console.log(body)
let list
if (body.playlist.trackIds.length == body.privileges.length) {
list = this.filterListDetail(body)
@@ -100,7 +97,7 @@ export default {
try {
list = (await (musicDetailApi as any).getList(body.playlist.trackIds.slice(rangeStart, limit * page).map(trackId => trackId.id))).list
} catch (err: any) {
console.log(err)
console.warn(`[wy] 歌单歌曲详情获取失败将重试(${tryNum + 1}): ${err.message}`)
if (err.message == 'try max num') {
throw err
} else {
@@ -108,7 +105,6 @@ export default {
}
}
}
// console.log(list)
return {
list,
page,
@@ -125,7 +121,6 @@ export default {
}
},
filterListDetail({ playlist: { tracks }, privileges }) {
// console.log(tracks, privileges)
const list: any[] = []
tracks.forEach((item, index) => {
const types: Array<{ type: string, size: string | null }> = []
@@ -218,7 +213,6 @@ export default {
}),
})
return this._requestObj_list!.promise.then(({ body }) => {
// console.log(body)
if (body.code !== this.successCode) return this.getList(sortId, tagId, page, ++tryNum)
return {
list: this.filterList(body.playlists),
@@ -230,7 +224,6 @@ export default {
})
},
filterList(rawData) {
// console.log(rawData)
return rawData.map(item => ({
play_count: formatPlayCount(item.playCount),
id: String(item.id),
@@ -254,7 +247,6 @@ export default {
form: weapi({}),
})
return this._requestObj_tags!.promise.then(({ body }) => {
// console.log(JSON.stringify(body))
if (body.code !== this.successCode) return this.getTag(++tryNum)
return this.filterTagInfo(body)
})
@@ -292,7 +284,6 @@ export default {
form: weapi({}),
})
return this._requestObj_hotTags!.promise.then(({ body }) => {
// console.log(JSON.stringify(body))
if (body.code !== this.successCode) return this.getTag(++tryNum)
return this.filterHotTagInfo(body.tags)
})
@@ -324,7 +315,6 @@ export default {
})
.promise.then(({ body }) => {
if (body.code != this.successCode) throw new Error('filed')
// console.log(body)
return {
list: this.filterList(body.result.playlists),
limit,
+1 -1
View File
@@ -3,7 +3,7 @@
// 未登录抛出清晰错误,不返回空列表
// 1) weapi/nuser/account/get → 当前用户 userId
// 2) weapi/user/playlist → 用户歌单列表(分页 limit/offset)
import { httpFetch } from '../request.ts'
import { httpFetch } from '../common/request.ts'
import { weapi } from './utils/crypto.ts'
import { formatPlayCount } from '../index.ts'
import { getCredentials, getWyCookie } from '../auth/store.ts'
+1 -9
View File
@@ -1,4 +1,4 @@
import { httpFetch } from '../../request.ts'
import { httpFetch } from '../../common/request.ts'
import { eapi } from './crypto.ts'
import { getWyCookie } from '../../auth/store.ts'
import type { HttpRequestObject } from '../../types.ts'
@@ -15,12 +15,4 @@ export const eapiRequest = (url: string, data: object): HttpRequestObject => {
},
form: eapi(url, data),
})
// requestObj.promise = requestObj.promise.then(({ body }) => {
// // console.log(raw)
// console.log(body)
// // console.log(eapiDecrypt(raw))
// // return eapiDecrypt(raw)
// return body
// })
// return requestObj
}