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:
2026-10-31 03:45:50 +08:00
parent 5c283a79fc
commit 6fe5c8c8d0
30 changed files with 1016 additions and 54 deletions
+18 -9
View File
@@ -35,6 +35,15 @@ function uploadPartUrl(uploadId: string, index: number): string {
return `${JAVA_API_PREFIX}/files/chunk/${encodeURIComponent(uploadId)}/part/${index}`
}
/** 兼容真实 axios 响应(body 在 .data)与测试桩(直接返回 body):统一取出 Java 包体。 */
function bodyOf<T>(response: unknown): JavaApiResponse<T> {
const candidate = (response as { data?: unknown } | null | undefined)?.data
if (candidate && typeof candidate === 'object' && 'success' in candidate) {
return candidate as JavaApiResponse<T>
}
return response as JavaApiResponse<T>
}
/** 单次 multipart 上传(小文件短链路)。超时按体积给,不再固定 120s。 */
async function singleUpload(
file: File,
@@ -68,7 +77,7 @@ async function singleUpload(
},
},
)
return response.data
return bodyOf<UploadFileVo>(response)
}
/**
@@ -81,22 +90,22 @@ async function chunkedUpload(
onProgress?: (percent: number) => void,
): Promise<JavaApiResponse<UploadFileVo>> {
const totalParts = Math.max(1, Math.ceil(file.size / UPLOAD_PART_SIZE))
const init = await http.post<JavaApiResponse<{ upload_id?: string }>>(
const init = bodyOf<{ upload_id?: string }>(await http.post(
`${JAVA_API_PREFIX}/files/chunk/init`,
null,
{ params: { fileName: file.name, totalParts, totalBytes: file.size } },
)
const uploadId = String(init.data?.data?.upload_id ?? '')
))
const uploadId = String(init.data?.upload_id ?? '')
if (!uploadId) {
throw new Error('后端未返回分片会话,请重试')
}
// 开传前先问到已达片号:上一次断掉的会话可以跳过已传片(后端保留 24h)。
// 这一问失败不再静默按"全缺"重传:断网/5xx 当场说清楚,别闷头把整包从 0 再传一遍。
const status = await http.get<JavaApiResponse<{ uploaded_parts?: unknown[] }>>(
const status = bodyOf<{ uploaded_parts?: unknown[] }>(await http.get(
`${JAVA_API_PREFIX}/files/chunk/${encodeURIComponent(uploadId)}`,
)
const arrived = status.data?.data?.uploaded_parts
))
const arrived = status.data?.uploaded_parts
const done = new Set<number>(Array.isArray(arrived) ? arrived.map((index) => Number(index)) : [])
const report = (partialBytes: number) => {
@@ -138,13 +147,13 @@ async function chunkedUpload(
if (options.relativePath) params.relativePath = options.relativePath
if (options.uploadToOss) params.uploadToOss = true
if (options.moduleType) params.moduleType = options.moduleType
const response = await http.post<JavaApiResponse<UploadFileVo>>(
const response = await http.post(
`${JAVA_API_PREFIX}/files/chunk/${encodeURIComponent(uploadId)}/complete`,
null,
{ params, timeout: 600_000 },
)
if (onProgress) onProgress(100)
return response.data
return bodyOf<UploadFileVo>(response)
}
export async function uploadTempFileToJava(