Skip to content

Commit 0194329

Browse files
committed
append
1 parent 2ac7357 commit 0194329

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ qiniu.compressImage(file, options).then(data => {
171171
* ProgressCompose 的信息如下
172172
* size: `number` chunk 的尺寸
173173
* loaded: `number` 已经发送完毕的尺寸
174-
* percent: `number` 进度比例,范围在 0 - 1
174+
* percent: `number` 进度比例,范围在 0 - 100
175175
* isCache?: `boolean` 是否使用的缓存
176176
* total: 包含 `loaded``total``percent` 三个属性:
177177
* total.loaded: `number`,已上传大小,单位为字节。
@@ -184,7 +184,7 @@ qiniu.compressImage(file, options).then(data => {
184184
* message: `string` 错误的信息。
185185
* stack: `string` 调用堆栈信息。
186186
* `QiniuRequestError` 继承自 `QiniuError`
187-
* data: `{[key:string]:any}` 服务端返回的错误信息,如果不是一个标准的 `json` 格式,则该字段为 `undefined`
187+
* data: `any` 服务端返回的错误信息,如果不是一个标准的 `json` 格式,则该字段为 `undefined`
188188
* reqId: `string` xhr 请求错误的 `X-Reqid`
189189
* code: `number` 请求错误状态码,可查阅码值对应 [说明](https://developer.qiniu.com/kodo/api/3928/error-responses)。
190190
* isRequestError: 固定为 `true`*不推荐使用,即将废弃*

src/errors/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export class QiniuRequestError extends QiniuError {
4545
/**
4646
* @description 发生错误时服务端返回的错误信息,如果返回不是一个合法的 json、则该字段为 undefined
4747
*/
48-
public data?: { [key: string]: any }
48+
public data?: any
4949

50-
constructor(public code: number, public reqId: string, message: string, data?: { [key: string]: any }) {
50+
constructor(public code: number, public reqId: string, message: string, data?: any) {
5151
super(QiniuErrorName.RequestError, message)
5252
this.data = data
5353
}

src/upload/base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface ProgressCompose {
9191
size: number
9292
loaded: number
9393
percent: number
94-
isCache?: boolean
94+
fromCache?: boolean
9595
}
9696

9797
export type XHRHandler = (xhr: XMLHttpRequest) => void
@@ -326,11 +326,11 @@ export default abstract class Base {
326326
})
327327
}
328328

329-
public getProgressInfoItem(loaded: number, size: number, isCache?: boolean): ProgressCompose {
329+
public getProgressInfoItem(loaded: number, size: number, fromCache?: boolean): ProgressCompose {
330330
return {
331331
size,
332332
loaded,
333-
isCache,
333+
fromCache,
334334
percent: loaded / size * 100
335335
}
336336
}

src/upload/resume.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Base, { Progress, UploadInfo, Extra } from './base'
66

77
export interface UploadedChunkStorage extends UploadChunkData {
88
size: number
9+
10+
fromCache?: boolean
911
}
1012

1113
export interface ChunkLoaded {
@@ -103,7 +105,7 @@ export default class Resume extends Base {
103105

104106
const shouldCheckMD5 = this.config.checkByMD5
105107
const reuseSaved = () => {
106-
this.usedCaches.push(index)
108+
info.fromCache = true
107109
this.updateChunkProgress(chunk.size, index)
108110
}
109111

@@ -248,11 +250,13 @@ export default class Resume extends Base {
248250
this.progress = {
249251
total: this.getProgressInfoItem(
250252
utils.sum(this.loaded.chunks) + this.loaded.mkFileProgress,
253+
// FIXME: 不准确的 fileSize
251254
this.file.size + 1 // 防止在 complete 未调用的时候进度显示 100%
252255
),
253256
chunks: this.chunks.map((chunk, index) => {
254-
const isCache = this.usedCaches.includes(index)
255-
return this.getProgressInfoItem(this.loaded.chunks[index], chunk.size, isCache)
257+
const info = this.uploadedList[index]
258+
const fromCache = info && info.fromCache
259+
return this.getProgressInfoItem(this.loaded.chunks[index], chunk.size, fromCache)
256260
}),
257261
uploadInfo: {
258262
id: this.uploadId,

0 commit comments

Comments
 (0)