新增热搜词、历史搜索记录

This commit is contained in:
lyswhut
2020-03-15 17:17:41 +08:00
parent 9d1270374e
commit 670533807a
29 changed files with 460 additions and 18 deletions
+26
View File
@@ -0,0 +1,26 @@
import { httpFetch } from '../../request'
import { weapi } from './utils/crypto'
export default {
_requestObj: null,
async getList(retryNum = 0) {
if (this._requestObj) this._requestObj.cancelHttp()
if (retryNum > 2) return Promise.reject(new Error('try max num'))
const _requestObj = httpFetch('https://music.163.com/weapi/search/hot', {
method: 'post',
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',
},
form: weapi({ type: 1111 }),
})
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.result.hots) }
},
filterList(rawList) {
return rawList.map(item => item.first)
},
}
+2
View File
@@ -4,11 +4,13 @@ import getLyric from './lyric'
import getMusicInfo from './musicInfo'
import musicSearch from './musicSearch'
import songList from './songList'
import hotSearch from './hotSearch'
const wy = {
leaderboard,
musicSearch,
songList,
hotSearch,
getMusicUrl(songInfo, type) {
return api_source('wy').getMusicUrl(songInfo, type)
},
@@ -81,7 +81,6 @@ export default {
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
if (limit != null) this.limit = limit
return this.musicSearch(str, page).then(result => {
// console.log(JSON.stringify(result))
if (!result || result.code !== 200) return this.search(str, page, { limit }, retryNum)
let list = this.handleResult(result.result.songs)