diff --git a/publish/changeLog.md b/publish/changeLog.md index d0f31de811..3d5efa479a 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -2,4 +2,7 @@ ### 修复 -- 修复由于旧版配置文件迁移出错导致的软件界面无法显示的问题 +- 修复歌曲下载列表无法加载的问题 +- 修复歌曲下载任务数大于最大下载任务数的问题 +- 修复某些情况下歌曲下载错误的问题 +- 修复下载列表数据没有被迁移直接被丢弃的问题 diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index d7eb9d145e..865caee510 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -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 } @@ -226,9 +225,8 @@ const actions = { } }, onFail(response) { - commit('onError', downloadInfo) - if (++tryNum[downloadInfo.key] > 2) { + commit('onError', downloadInfo) _this.dispatch('download/startTask') return } diff --git a/src/renderer/store/state.js b/src/renderer/store/state.js index 98775fcfd0..724f221ab6 100644 --- a/src/renderer/store/state.js +++ b/src/renderer/store/state.js @@ -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) diff --git a/src/renderer/utils/download/Downloader.js b/src/renderer/utils/download/Downloader.js index 1127f180ad..2be98891dd 100644 --- a/src/renderer/utils/download/Downloader.js +++ b/src/renderer/utils/download/Downloader.js @@ -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) => { @@ -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() @@ -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) + }) }) }