修复请求超时的逻辑处理Bug
parent
ea10dd68a3
commit
29855b2b6e
|
@ -12,4 +12,5 @@
|
||||||
|
|
||||||
### 修复
|
### 修复
|
||||||
|
|
||||||
- 修复一些小Bug
|
- 修复请求超时的逻辑处理Bug,尝试修复请求无法取消导致的正在播放的歌曲与界面显示的信息不一致的问题
|
||||||
|
- 修复其他一些小Bug
|
||||||
|
|
|
@ -18,10 +18,16 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import dnscache from 'dnscache'
|
||||||
import { mapMutations, mapGetters, mapActions } from 'vuex'
|
import { mapMutations, mapGetters, mapActions } from 'vuex'
|
||||||
import { rendererOn } from '../common/icp'
|
import { rendererOn } from '../common/icp'
|
||||||
import { isLinux } from '../common/utils'
|
import { isLinux } from '../common/utils'
|
||||||
window.ELECTRON_DISABLE_SECURITY_WARNINGS = process.env.ELECTRON_DISABLE_SECURITY_WARNINGS
|
window.ELECTRON_DISABLE_SECURITY_WARNINGS = process.env.ELECTRON_DISABLE_SECURITY_WARNINGS
|
||||||
|
dnscache({
|
||||||
|
enable: true,
|
||||||
|
ttl: 21600,
|
||||||
|
cachesize: 1000,
|
||||||
|
})
|
||||||
let win
|
let win
|
||||||
let body
|
let body
|
||||||
if (!isLinux) {
|
if (!isLinux) {
|
||||||
|
|
|
@ -8,10 +8,7 @@ export default {
|
||||||
_musicTempSearchRequestObj: null,
|
_musicTempSearchRequestObj: null,
|
||||||
_musicTempSearchPromiseCancelFn: null,
|
_musicTempSearchPromiseCancelFn: null,
|
||||||
tempSearch(str) {
|
tempSearch(str) {
|
||||||
if (this._musicTempSearchRequestObj != null) {
|
this.cancelTempSearch()
|
||||||
cancelHttp(this._musicTempSearchRequestObj)
|
|
||||||
this._musicTempSearchPromiseCancelFn(new Error('取消http请求'))
|
|
||||||
}
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._musicTempSearchPromiseCancelFn = reject
|
this._musicTempSearchPromiseCancelFn = reject
|
||||||
this._musicTempSearchRequestObj = httpGet(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`, (err, resp, body) => {
|
this._musicTempSearchRequestObj = httpGet(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`, (err, resp, body) => {
|
||||||
|
|
|
@ -5,13 +5,6 @@ import { requestMsg } from './message'
|
||||||
import { bHh } from './music/options'
|
import { bHh } from './music/options'
|
||||||
// import fs from 'fs'
|
// import fs from 'fs'
|
||||||
|
|
||||||
import dnscache from 'dnscache'
|
|
||||||
dnscache({
|
|
||||||
enable: true,
|
|
||||||
ttl: 21600,
|
|
||||||
cachesize: 1000,
|
|
||||||
})
|
|
||||||
|
|
||||||
const defaultHeaders = {
|
const defaultHeaders = {
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
|
||||||
}
|
}
|
||||||
|
@ -26,7 +19,7 @@ const defaultHeaders = {
|
||||||
const buildHttpPromose = (url, options) => {
|
const buildHttpPromose = (url, options) => {
|
||||||
let requestObj
|
let requestObj
|
||||||
let cancelFn
|
let cancelFn
|
||||||
const p = new Promise((resolve, reject) => {
|
let p = new Promise((resolve, reject) => {
|
||||||
cancelFn = reject
|
cancelFn = reject
|
||||||
debugRequest && console.log(`\n---send request------${url}------------`)
|
debugRequest && console.log(`\n---send request------${url}------------`)
|
||||||
requestObj = fetchData(url, options.method, options, (err, resp, body) => {
|
requestObj = fetchData(url, options.method, options, (err, resp, body) => {
|
||||||
|
@ -36,11 +29,12 @@ const buildHttpPromose = (url, options) => {
|
||||||
requestObj = null
|
requestObj = null
|
||||||
cancelFn = null
|
cancelFn = null
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err.code)
|
// console.log('出错', err.code)
|
||||||
if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') {
|
if (err.code === 'ETIMEDOUT' || err.code == 'ESOCKETTIMEDOUT') {
|
||||||
const { promise, cancelHttp } = httpFetch(url, options)
|
const { promise, cancelHttp } = httpFetch(url, options)
|
||||||
obj.cancelHttp = cancelHttp
|
obj.cancelHttp = cancelHttp
|
||||||
promise.then()
|
promise.then(resp => resolve(resp)).catch(err => reject(err))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return reject(err)
|
return reject(err)
|
||||||
}
|
}
|
||||||
|
@ -51,11 +45,11 @@ const buildHttpPromose = (url, options) => {
|
||||||
promise: p,
|
promise: p,
|
||||||
cancelHttp() {
|
cancelHttp() {
|
||||||
if (!requestObj) return
|
if (!requestObj) return
|
||||||
console.log('cancel')
|
|
||||||
cancelHttp(requestObj)
|
|
||||||
cancelFn(new Error(requestMsg.cancelRequest))
|
cancelFn(new Error(requestMsg.cancelRequest))
|
||||||
|
cancelHttp(requestObj)
|
||||||
requestObj = null
|
requestObj = null
|
||||||
cancelFn = null
|
cancelFn = null
|
||||||
|
p = null
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
|
|
Loading…
Reference in New Issue