- 移除 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
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import type { HttpRequestObject } from '../types.ts'
|
|
import { httpFetch } from '../request.ts'
|
|
|
|
export default {
|
|
// regExps: {
|
|
// relWord: /RELWORD=(.+)/,
|
|
// },
|
|
requestObj: null as HttpRequestObject | null,
|
|
tipSearch(str) {
|
|
this.cancelTipSearch()
|
|
this.requestObj = httpFetch(`https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?is_xml=0&format=json&key=${encodeURIComponent(str)}&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0`, {
|
|
headers: {
|
|
Referer: 'https://y.qq.com/portal/player.html',
|
|
},
|
|
})
|
|
return this.requestObj.promise.then(({ statusCode, body }) => {
|
|
if (statusCode != 200 || body.code != 0) return Promise.reject(new Error('请求失败'))
|
|
return body.data
|
|
})
|
|
},
|
|
handleResult(rawData) {
|
|
return rawData.map(info => `${info.name} - ${info.singer}`)
|
|
},
|
|
cancelTipSearch() {
|
|
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
|
},
|
|
async search(str) {
|
|
return this.tipSearch(str).then(result => this.handleResult(result.song.itemlist))
|
|
},
|
|
}
|