- 移除 bd/mg 两平台及磁盘残留产物;清理 api-test 死脚本、musicSdk/message+options 死模块、infSign vendor - musicSdk/ 改名 sdk/;src/common、src/auth、src/apis 整体移入 sdk/,依赖方向定为 src → sdk 严格单向 - src/ 手写 JS 全量转 .ts,删除 JS 类型垫片 modules.d.ts;源码 import 统一 .ts 后缀 - Node 原生类型剥离直接运行 .ts(engines >=22.18),取消 tsc 发射产物,tsc 仅类型检查(pnpm typecheck) - 删除 kwdes 备用实现与 src/index.ts 转发垫片;测试移至 test/smoke-test.ts - common/request.ts 补显式导出类型;修复 set-cookie 单值形态、ApiError 类字段等隐患 验证:tsc 零错误,smoke-test 41/41
84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
import { httpFetch } from '../request.ts'
|
|
import { dateFormat2 } from '../index.ts'
|
|
import type { HttpRequestObject } from '../types.ts'
|
|
|
|
export default {
|
|
_requestObj: null as HttpRequestObject | null,
|
|
_requestObj2: null as HttpRequestObject | null,
|
|
async getComment({ songmid }, page = 1, limit = 20) {
|
|
if (this._requestObj) this._requestObj.cancelHttp()
|
|
|
|
const _requestObj = httpFetch(`http://ncomment.kuwo.cn/com.s?f=web&type=get_comment&aapiver=1&prod=kwplayer_ar_10.5.2.0&digest=15&sid=${songmid}&start=${limit * (page - 1)}&msgflag=1&count=${limit}&newver=3&uid=0`, {
|
|
headers: {
|
|
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9;)',
|
|
},
|
|
})
|
|
const { body, statusCode } = await _requestObj.promise
|
|
if (statusCode != 200 || body.code != '200') throw new Error('获取评论失败')
|
|
// console.log(body)
|
|
|
|
const total = body.comments_counts
|
|
return {
|
|
source: 'kw',
|
|
comments: this.filterComment(body.comments),
|
|
total,
|
|
page,
|
|
limit,
|
|
maxPage: Math.ceil(total / limit) || 1,
|
|
}
|
|
},
|
|
async getHotComment({ songmid }, page = 1, limit = 100) {
|
|
if (this._requestObj2) this._requestObj2.cancelHttp()
|
|
|
|
const _requestObj2 = httpFetch(`http://ncomment.kuwo.cn/com.s?f=web&type=get_rec_comment&aapiver=1&prod=kwplayer_ar_10.5.2.0&digest=15&sid=${songmid}&start=${limit * (page - 1)}&msgflag=1&count=${limit}&newver=3&uid=0`, {
|
|
headers: {
|
|
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9;)',
|
|
},
|
|
})
|
|
const { body, statusCode } = await _requestObj2.promise
|
|
if (statusCode != 200 || body.code != '200') throw new Error('获取热门评论失败')
|
|
// console.log(body)
|
|
|
|
const total = body.hot_comments_counts
|
|
return {
|
|
source: 'kw',
|
|
comments: this.filterComment(body.hot_comments),
|
|
total,
|
|
page,
|
|
limit,
|
|
maxPage: Math.ceil(total / limit) || 1,
|
|
}
|
|
},
|
|
filterComment(rawList) {
|
|
if (!rawList) return []
|
|
return rawList.map(item => {
|
|
return {
|
|
id: item.id,
|
|
text: item.msg,
|
|
time: item.time,
|
|
timeStr: dateFormat2(Number(item.time) * 1000),
|
|
userName: item.u_name,
|
|
avatar: item.u_pic,
|
|
userId: item.u_id,
|
|
likedCount: item.like_num,
|
|
images: item.mpic ? [decodeURIComponent(item.mpic)] : [],
|
|
reply: item.child_comments
|
|
? item.child_comments.map(i => {
|
|
return {
|
|
id: i.id,
|
|
text: i.msg,
|
|
time: i.time,
|
|
timeStr: dateFormat2(Number(i.time) * 1000),
|
|
userName: i.u_name,
|
|
avatar: i.u_pic,
|
|
userId: i.u_id,
|
|
likedCount: i.like_num,
|
|
images: i.mpic ? [i.mpic] : [],
|
|
}
|
|
})
|
|
: [],
|
|
}
|
|
})
|
|
},
|
|
}
|