Skip to content

Commit 1bfa8dc

Browse files
committed
bug 修复
1 parent 1b381af commit 1bfa8dc

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

publish/changeLog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
### 修复
44

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

src/renderer/store/modules/download.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ const actions = {
210210
console.log('on complate')
211211
},
212212
onError(err) {
213-
// console.log(err.code, err.message)
214-
commit('onError', downloadInfo)
215213
// console.log(tryNum[downloadInfo.key])
216214
if (++tryNum[downloadInfo.key] > 2) {
215+
commit('onError', downloadInfo)
217216
_this.dispatch('download/startTask')
218217
return
219218
}
@@ -226,9 +225,8 @@ const actions = {
226225
}
227226
},
228227
onFail(response) {
229-
commit('onError', downloadInfo)
230-
231228
if (++tryNum[downloadInfo.key] > 2) {
229+
commit('onError', downloadInfo)
232230
_this.dispatch('download/startTask')
233231
return
234232
}

src/renderer/store/state.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ if (!electronStore_config.get('version') && electronStore_config.get('setting'))
1919
if (list.loveList) electronStore_list.set('loveList', list.loveList)
2020
electronStore_config.delete('list')
2121
}
22-
if (electronStore_config.get('download')) electronStore_config.delete('download')
22+
const downloadList = electronStore_config.get('download')
23+
if (downloadList) {
24+
if (downloadList.list) electronStore_list.set('downloadList', downloadList.list)
25+
electronStore_config.delete('download')
26+
}
2327
}
2428
const { version: settingVersion, setting } = updateSetting(electronStore_config.get('setting'), electronStore_config.get('version'))
2529
electronStore_config.set('version', settingVersion)

src/renderer/utils/download/Downloader.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Task extends EventEmitter {
5959
__init() {
6060
this.status = STATUS.init
6161
const { path, startByte, endByte } = this.chunkInfo
62-
if (startByte) this.requestOptions.headers.range = `bytes=${startByte}-${endByte}`
62+
if (startByte != null) this.requestOptions.headers.range = `bytes=${startByte}-${endByte}`
6363
return new Promise((resolve, reject) => {
6464
if (!path) return resolve()
6565
fs.stat(path, (errStat, stats) => {
@@ -110,6 +110,16 @@ class Task extends EventEmitter {
110110
this.request = request(url, options)
111111
.on('response', response => {
112112
if (response.statusCode !== 200 && response.statusCode !== 206) {
113+
if (response.statusCode == 416) {
114+
fs.unlink(this.chunkInfo.path, async err => {
115+
await this.__handleError(new Error(response.statusMessage))
116+
this.chunkInfo.startByte = 0
117+
this.resumeLastChunk = null
118+
this.progress.downloaded = 0
119+
if (err) this.__handleError(err)
120+
})
121+
return
122+
}
113123
this.status = STATUS.failed
114124
this.emit('fail', response)
115125
this.__closeRequest()
@@ -154,9 +164,14 @@ class Task extends EventEmitter {
154164
this.ws = fs.createWriteStream(this.chunkInfo.path, options)
155165

156166
this.ws.on('finish', () => this.__closeWriteStream())
157-
this.ws.on('error', async err => {
158-
await this.__handleError(err)
159-
fs.unlink(this.chunkInfo.path, () => this.__handleError(err))
167+
this.ws.on('error', err => {
168+
fs.unlink(this.chunkInfo.path, async unlinkErr => {
169+
await this.__handleError(err)
170+
this.chunkInfo.startByte = 0
171+
this.resumeLastChunk = null
172+
this.progress.downloaded = 0
173+
if (unlinkErr) this.__handleError(unlinkErr)
174+
})
160175
})
161176
}
162177

0 commit comments

Comments
 (0)