-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 修复kw搜索联想词 * 完善 --------- Co-authored-by: lyswhut <[email protected]>
- Loading branch information
Showing
4 changed files
with
58 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
### 修复 | ||
|
||
- 修复字体设置某些字体无法应用的问题 | ||
|
||
- 修复搜索提示功能失效的问题(#1452, @Folltoshe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
import { decodeName } from '../../index' | ||
import { tokenRequest } from './util' | ||
// import { decodeName } from '../../index' | ||
// import { tokenRequest } from './util' | ||
import { httpFetch } from '../../request' | ||
|
||
export default { | ||
regExps: { | ||
relWord: /RELWORD=(.+)/, | ||
}, | ||
requestObj: null, | ||
async tipSearchBySong(str) { | ||
// 报错403,加了referer还是有问题(直接换一个 | ||
// this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`) | ||
|
||
this.cancelTipSearch() | ||
this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`) | ||
return this.requestObj.promise.then(({ body }) => { | ||
// console.log(body) | ||
if (body.code !== 200) return Promise.reject(new Error('请求失败')) | ||
return body | ||
this.requestObj = httpFetch(`https://tips.kuwo.cn/t.s?corp=kuwo&newver=3&p2p=1¬race=0&c=mbox&w=${encodeURIComponent(str)}&encoding=utf8&rformat=json`, { | ||
Referer: 'http://www.kuwo.cn/', | ||
}) | ||
return this.requestObj.promise.then(({ body, statusCode }) => { | ||
if (statusCode != 200 || !body.WORDITEMS) return Promise.reject(new Error('请求失败')) | ||
return body.WORDITEMS | ||
}) | ||
}, | ||
handleResult(rawData) { | ||
return rawData.map(info => { | ||
let matchResult = info.match(this.regExps.relWord) | ||
return matchResult ? decodeName(matchResult[1]) : '' | ||
}) | ||
return rawData.map(item => item.RELWORD) | ||
}, | ||
cancelTipSearch() { | ||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp() | ||
}, | ||
async search(str) { | ||
return this.tipSearchBySong(str).then(result => this.handleResult(result.data)) | ||
return this.tipSearchBySong(str).then(result => this.handleResult(result)) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters