@@ -6,8 +6,6 @@ import Base, { Progress, UploadInfo, Extra } from './base'
6
6
7
7
export interface UploadedChunkStorage extends UploadChunkData {
8
8
size : number
9
-
10
- fromCache ?: boolean
11
9
}
12
10
13
11
export interface ChunkLoaded {
@@ -46,6 +44,11 @@ export default class Resume extends Base {
46
44
*/
47
45
private chunks : Blob [ ]
48
46
47
+ /**
48
+ * @description 使用的缓存的 chunks
49
+ */
50
+ private usedCacheList : boolean [ ]
51
+
49
52
/**
50
53
* @description 来自缓存的上传信息
51
54
*/
@@ -121,8 +124,10 @@ export default class Resume extends Base {
121
124
122
125
const shouldCheckMD5 = this . config . checkByMD5
123
126
const reuseSaved = ( ) => {
124
- info . fromCache = true
125
- this . uploadedList [ index ] = info
127
+ this . uploadedList [ index ] = { ...info }
128
+ this . usedCacheList [ index ] = true
129
+ this . updateLocalCache ( )
130
+
126
131
this . updateChunkProgress ( chunk . size , index )
127
132
}
128
133
@@ -140,9 +145,6 @@ export default class Resume extends Base {
140
145
return
141
146
}
142
147
143
- // 有缓存但是没有使用则调整标记
144
- if ( info ) { info . fromCache = false }
145
-
146
148
const onProgress = ( data : Progress ) => {
147
149
this . updateChunkProgress ( data . loaded , index )
148
150
}
@@ -175,10 +177,7 @@ export default class Resume extends Base {
175
177
size : chunk . size
176
178
}
177
179
178
- utils . setLocalFileInfo ( this . getLocalKey ( ) , {
179
- id : this . uploadId ,
180
- data : this . uploadedList
181
- } , this . logger )
180
+ this . updateLocalCache ( )
182
181
}
183
182
184
183
private async mkFileReq ( ) {
@@ -211,6 +210,7 @@ export default class Resume extends Base {
211
210
212
211
private async initBeforeUploadChunks ( ) {
213
212
this . uploadedList = [ ]
213
+ this . usedCacheList = [ ]
214
214
const cachedInfo = utils . getLocalFileInfo ( this . getLocalKey ( ) , this . logger )
215
215
216
216
// 分片必须和当时使用的 uploadId 配套,所以断点续传需要把本地存储的 uploadId 拿出来
@@ -257,6 +257,13 @@ export default class Resume extends Base {
257
257
return utils . createLocalKey ( this . file . name , this . key , this . file . size )
258
258
}
259
259
260
+ private updateLocalCache ( ) {
261
+ utils . setLocalFileInfo ( this . getLocalKey ( ) , {
262
+ id : this . uploadId ,
263
+ data : this . uploadedList
264
+ } , this . logger )
265
+ }
266
+
260
267
private updateChunkProgress ( loaded : number , index : number ) {
261
268
this . loaded . chunks [ index ] = loaded
262
269
this . notifyResumeProgress ( )
@@ -275,8 +282,7 @@ export default class Resume extends Base {
275
282
this . file . size + 1 // 防止在 complete 未调用的时候进度显示 100%
276
283
) ,
277
284
chunks : this . chunks . map ( ( chunk , index ) => {
278
- const info = this . uploadedList [ index ]
279
- const fromCache = info && info . fromCache
285
+ const fromCache = this . usedCacheList [ index ]
280
286
return this . getProgressInfoItem ( this . loaded . chunks [ index ] , chunk . size , fromCache )
281
287
} ) ,
282
288
uploadInfo : {
0 commit comments