chore(web): 合并 release 分片上传修复
This commit is contained in:
commit
f78960fcce
1 file changed
+8
-6
@@ -32,8 +32,9 @@ export async function uploadFile(file: File, options: UploadFileOptions = {}): P
|
|||||||
bizType
|
bizType
|
||||||
})
|
})
|
||||||
const info = initRes.data
|
const info = initRes.data
|
||||||
|
const chunkSize = Number(info.chunkSize)
|
||||||
options.onSession?.(info.uploadId)
|
options.onSession?.(info.uploadId)
|
||||||
const total = Math.max(info.totalChunks, 1)
|
const total = Math.max(Number(info.totalChunks), 1)
|
||||||
const pending: number[] = Array.from({ length: total }, (_, index) => index)
|
const pending: number[] = Array.from({ length: total }, (_, index) => index)
|
||||||
let finished = 0
|
let finished = 0
|
||||||
|
|
||||||
@@ -41,8 +42,8 @@ export async function uploadFile(file: File, options: UploadFileOptions = {}): P
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
const index = pending.shift()
|
const index = pending.shift()
|
||||||
if (index === undefined) return
|
if (index === undefined) return
|
||||||
const start = index * info.chunkSize
|
const start = index * chunkSize
|
||||||
const chunk = file.slice(start, Math.min(start + info.chunkSize, file.size))
|
const chunk = file.slice(start, Math.min(start + chunkSize, file.size))
|
||||||
await uploadChunkApi(info.uploadId, index, chunk, file.name)
|
await uploadChunkApi(info.uploadId, index, chunk, file.name)
|
||||||
finished += 1
|
finished += 1
|
||||||
onProgress?.(Math.min(95, Math.round((finished / total) * 95)))
|
onProgress?.(Math.min(95, Math.round((finished / total) * 95)))
|
||||||
@@ -68,7 +69,8 @@ export async function resumeUpload(
|
|||||||
): Promise<MediaAsset> {
|
): Promise<MediaAsset> {
|
||||||
const { concurrency = 3, onProgress } = options
|
const { concurrency = 3, onProgress } = options
|
||||||
const progress = (await getUploadProgressApi(uploadId)).data
|
const progress = (await getUploadProgressApi(uploadId)).data
|
||||||
const total = Math.max(progress.totalChunks, 1)
|
const chunkSize = Number(progress.chunkSize)
|
||||||
|
const total = Math.max(Number(progress.totalChunks), 1)
|
||||||
const received = Math.min(progress.receivedChunks || 0, total)
|
const received = Math.min(progress.receivedChunks || 0, total)
|
||||||
const pending: number[] = []
|
const pending: number[] = []
|
||||||
for (let index = received; index < total; index += 1) {
|
for (let index = received; index < total; index += 1) {
|
||||||
@@ -81,8 +83,8 @@ export async function resumeUpload(
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
const index = pending.shift()
|
const index = pending.shift()
|
||||||
if (index === undefined) return
|
if (index === undefined) return
|
||||||
const start = index * progress.chunkSize
|
const start = index * chunkSize
|
||||||
const chunk = file.slice(start, Math.min(start + progress.chunkSize, file.size))
|
const chunk = file.slice(start, Math.min(start + chunkSize, file.size))
|
||||||
await uploadChunkApi(uploadId, index, chunk, file.name)
|
await uploadChunkApi(uploadId, index, chunk, file.name)
|
||||||
finished += 1
|
finished += 1
|
||||||
onProgress?.(Math.min(95, Math.round((finished / total) * 95)))
|
onProgress?.(Math.min(95, Math.round((finished / total) * 95)))
|
||||||
|
|||||||
Reference in new issue
Block a user