Skip to content

Commit

Permalink
bug 修复
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Jan 22, 2020
1 parent 1b381af commit 1bfa8dc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
5 changes: 4 additions & 1 deletion publish/changeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

### 修复

- 修复由于旧版配置文件迁移出错导致的软件界面无法显示的问题
- 修复歌曲下载列表无法加载的问题
- 修复歌曲下载任务数大于最大下载任务数的问题
- 修复某些情况下歌曲下载错误的问题
- 修复下载列表数据没有被迁移直接被丢弃的问题
6 changes: 2 additions & 4 deletions src/renderer/store/modules/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ const actions = {
console.log('on complate')
},
onError(err) {
// console.log(err.code, err.message)
commit('onError', downloadInfo)
// console.log(tryNum[downloadInfo.key])
if (++tryNum[downloadInfo.key] > 2) {
commit('onError', downloadInfo)
_this.dispatch('download/startTask')
return
}
Expand All @@ -226,9 +225,8 @@ const actions = {
}
},
onFail(response) {
commit('onError', downloadInfo)

if (++tryNum[downloadInfo.key] > 2) {
commit('onError', downloadInfo)
_this.dispatch('download/startTask')
return
}
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/store/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ if (!electronStore_config.get('version') && electronStore_config.get('setting'))
if (list.loveList) electronStore_list.set('loveList', list.loveList)
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'))
electronStore_config.set('version', settingVersion)
Expand Down
23 changes: 19 additions & 4 deletions src/renderer/utils/download/Downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Task extends EventEmitter {
__init() {
this.status = STATUS.init
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) => {
if (!path) return resolve()
fs.stat(path, (errStat, stats) => {
Expand Down Expand Up @@ -110,6 +110,16 @@ class Task extends EventEmitter {
this.request = request(url, options)
.on('response', response => {
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.emit('fail', response)
this.__closeRequest()
Expand Down Expand Up @@ -154,9 +164,14 @@ class Task extends EventEmitter {
this.ws = fs.createWriteStream(this.chunkInfo.path, options)

this.ws.on('finish', () => this.__closeWriteStream())
this.ws.on('error', async err => {
await this.__handleError(err)
fs.unlink(this.chunkInfo.path, () => this.__handleError(err))
this.ws.on('error', err => {
fs.unlink(this.chunkInfo.path, async unlinkErr => {
await this.__handleError(err)
this.chunkInfo.startByte = 0
this.resumeLastChunk = null
this.progress.downloaded = 0
if (unlinkErr) this.__handleError(unlinkErr)
})
})
}

Expand Down

0 comments on commit 1bfa8dc

Please sign in to comment.