feat(phase-3,4): 证据件服务端落点与两前端大档分片接线
- 后端新增 evidence 模块(V182 证据表/独立桶/超管读取面/内部登记)与 application.yml evidence 块;管理员四端点逐个 requireSuperAdmin。 - 分片通道补 @Scheduled 回收与 LocalTempCleanupService 的 chunk-uploads 覆盖; 版本/教程 confirm 接受 file_key,把拼装件搬进 client 桶后落库。 - 用户端 9MB 视频改走 uploadTempFileToJava 分片;后管版本/教程 >8MB 走分片, 小文件仍走原 presign 直传。 - 激活 Phase 3/4 后端与两前端预置契约。
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { http, unwrap } from '@/api/http'
|
||||
|
||||
/** 大档分片阈值(AC-11):8MB 以上不再一次 PUT 直传,断点续传由服务端 chunk 通道承担。 */
|
||||
export const CHUNK_UPLOAD_THRESHOLD = 8 * 1024 * 1024
|
||||
export const CHUNK_UPLOAD_PART_SIZE = 8 * 1024 * 1024
|
||||
|
||||
function partUrl(uploadId: string, index: number): string {
|
||||
return `/api/files/chunk/${encodeURIComponent(uploadId)}/part/${index}`
|
||||
}
|
||||
|
||||
/** 后管大档上传(版本包/教程包共用):init → GET 已达片号 → 逐片 POST → complete。 */
|
||||
export async function uploadFileInChunks(
|
||||
file: Blob,
|
||||
fileName: string,
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<Record<string, unknown>> {
|
||||
const totalParts = Math.max(1, Math.ceil(file.size / CHUNK_UPLOAD_PART_SIZE))
|
||||
const initResponse = await http.post('/api/files/chunk/init', null, {
|
||||
params: { fileName, totalParts, totalBytes: file.size },
|
||||
timeout: 120_000 + Math.ceil(file.size / (1024 * 1024)) * 15_000,
|
||||
})
|
||||
const init = (unwrap(initResponse.data) ?? {}) as Record<string, unknown>
|
||||
const uploadId = String(init.upload_id ?? '')
|
||||
if (!uploadId) {
|
||||
throw new Error('后端未返回分片会话,请重试')
|
||||
}
|
||||
|
||||
const statusResponse = await http.get(`/api/files/chunk/${encodeURIComponent(uploadId)}`)
|
||||
const status = (unwrap(statusResponse.data) ?? {}) as Record<string, unknown>
|
||||
const arrived = new Set<number>(
|
||||
Array.isArray(status.uploaded_parts) ? status.uploaded_parts.map((value) => Number(value)) : [],
|
||||
)
|
||||
|
||||
for (let index = 0; index < totalParts; index += 1) {
|
||||
if (arrived.has(index)) {
|
||||
continue
|
||||
}
|
||||
const blob = file.slice(index * CHUNK_UPLOAD_PART_SIZE,
|
||||
Math.min(file.size, (index + 1) * CHUNK_UPLOAD_PART_SIZE))
|
||||
const form = new FormData()
|
||||
form.append('file', blob, `part-${index}`)
|
||||
await http.post(partUrl(uploadId, index), form, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
timeout: 120_000 + Math.ceil(file.size / (1024 * 1024)) * 15_000,
|
||||
onUploadProgress: (event) => {
|
||||
if (!onProgress) return
|
||||
const perPart = Math.round(((index + (event.loaded || 0) / Math.max(blob.size, 1)) / totalParts) * 100)
|
||||
onProgress(Math.min(perPart, 99))
|
||||
},
|
||||
})
|
||||
arrived.add(index)
|
||||
}
|
||||
|
||||
const completeResponse = await http.post(
|
||||
`/api/files/chunk/${encodeURIComponent(uploadId)}/complete`, null, { timeout: 600_000 })
|
||||
if (onProgress) onProgress(100)
|
||||
return (unwrap(completeResponse.data) ?? {}) as Record<string, unknown>
|
||||
}
|
||||
Reference in New Issue
Block a user