bug 修复

pull/166/head
lyswhut 2020-01-23 01:26:46 +08:00
parent 1b381af7a7
commit 1bfa8dcb3f
4 changed files with 30 additions and 10 deletions

View File

@ -2,4 +2,7 @@
### 修复 ### 修复
- 修复由于旧版配置文件迁移出错导致的软件界面无法显示的问题 - 修复歌曲下载列表无法加载的问题
- 修复歌曲下载任务数大于最大下载任务数的问题
- 修复某些情况下歌曲下载错误的问题
- 修复下载列表数据没有被迁移直接被丢弃的问题

View File

@ -210,10 +210,9 @@ const actions = {
console.log('on complate') console.log('on complate')
}, },
onError(err) { onError(err) {
// console.log(err.code, err.message)
commit('onError', downloadInfo)
// console.log(tryNum[downloadInfo.key]) // console.log(tryNum[downloadInfo.key])
if (++tryNum[downloadInfo.key] > 2) { if (++tryNum[downloadInfo.key] > 2) {
commit('onError', downloadInfo)
_this.dispatch('download/startTask') _this.dispatch('download/startTask')
return return
} }
@ -226,9 +225,8 @@ const actions = {
} }
}, },
onFail(response) { onFail(response) {
commit('onError', downloadInfo)
if (++tryNum[downloadInfo.key] > 2) { if (++tryNum[downloadInfo.key] > 2) {
commit('onError', downloadInfo)
_this.dispatch('download/startTask') _this.dispatch('download/startTask')
return return
} }

View File

@ -19,7 +19,11 @@ if (!electronStore_config.get('version') && electronStore_config.get('setting'))
if (list.loveList) electronStore_list.set('loveList', list.loveList) if (list.loveList) electronStore_list.set('loveList', list.loveList)
electronStore_config.delete('list') electronStore_config.delete('list')
} }
if (electronStore_config.get('download')) electronStore_config.delete('download') const downloadList = electronStore_config.get('download')
if (downloadList) {
if (downloadList.list) electronStore_list.set('downloadList', downloadList.list)
electronStore_config.delete('download')
}
} }
const { version: settingVersion, setting } = updateSetting(electronStore_config.get('setting'), electronStore_config.get('version')) const { version: settingVersion, setting } = updateSetting(electronStore_config.get('setting'), electronStore_config.get('version'))
electronStore_config.set('version', settingVersion) electronStore_config.set('version', settingVersion)

View File

@ -59,7 +59,7 @@ class Task extends EventEmitter {
__init() { __init() {
this.status = STATUS.init this.status = STATUS.init
const { path, startByte, endByte } = this.chunkInfo const { path, startByte, endByte } = this.chunkInfo
if (startByte) this.requestOptions.headers.range = `bytes=${startByte}-${endByte}` if (startByte != null) this.requestOptions.headers.range = `bytes=${startByte}-${endByte}`
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!path) return resolve() if (!path) return resolve()
fs.stat(path, (errStat, stats) => { fs.stat(path, (errStat, stats) => {
@ -110,6 +110,16 @@ class Task extends EventEmitter {
this.request = request(url, options) this.request = request(url, options)
.on('response', response => { .on('response', response => {
if (response.statusCode !== 200 && response.statusCode !== 206) { if (response.statusCode !== 200 && response.statusCode !== 206) {
if (response.statusCode == 416) {
fs.unlink(this.chunkInfo.path, async err => {
await this.__handleError(new Error(response.statusMessage))
this.chunkInfo.startByte = 0
this.resumeLastChunk = null
this.progress.downloaded = 0
if (err) this.__handleError(err)
})
return
}
this.status = STATUS.failed this.status = STATUS.failed
this.emit('fail', response) this.emit('fail', response)
this.__closeRequest() this.__closeRequest()
@ -154,9 +164,14 @@ class Task extends EventEmitter {
this.ws = fs.createWriteStream(this.chunkInfo.path, options) this.ws = fs.createWriteStream(this.chunkInfo.path, options)
this.ws.on('finish', () => this.__closeWriteStream()) this.ws.on('finish', () => this.__closeWriteStream())
this.ws.on('error', async err => { this.ws.on('error', err => {
await this.__handleError(err) fs.unlink(this.chunkInfo.path, async unlinkErr => {
fs.unlink(this.chunkInfo.path, () => this.__handleError(err)) await this.__handleError(err)
this.chunkInfo.startByte = 0
this.resumeLastChunk = null
this.progress.downloaded = 0
if (unlinkErr) this.__handleError(unlinkErr)
})
}) })
} }