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>
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
/** 教程包接口适配(教程管理页):列表 / 直传预签名 / 确认 / 删除。 */
|
||||
import axios from 'axios'
|
||||
import { http, unwrap } from '@/api/http'
|
||||
import { CHUNK_UPLOAD_THRESHOLD, uploadFileInChunks } from '@/api/chunk-upload'
|
||||
import { parseTutorialPackageList, parseTutorialPackageUpload } from './tutorial-model.ts'
|
||||
import type { TutorialPackageItem, TutorialPackageList } from './tutorial-dto.ts'
|
||||
|
||||
@@ -9,6 +10,8 @@ export const TUTORIAL_UPLOAD_ENDPOINT = '/api/admin/tutorial'
|
||||
export const TUTORIAL_PRESIGN_ENDPOINT = `${TUTORIAL_UPLOAD_ENDPOINT}/presign`
|
||||
export const TUTORIAL_CONFIRM_ENDPOINT = `${TUTORIAL_UPLOAD_ENDPOINT}/confirm`
|
||||
export const TUTORIAL_DELETE_ENDPOINT = `${TUTORIAL_UPLOAD_ENDPOINT}/delete`
|
||||
/** 大档分片通道(AC-11):>8MB 的教程包走这里,不再一次性 presign PUT。 */
|
||||
export const TUTORIAL_CHUNK_ENDPOINT = '/api/files/chunk'
|
||||
|
||||
/** MinIO 直传专用实例:不带 cookie、不挂 401 跳登录拦截器(预签名过期/签名失败不能误判会话过期);大 zip 给足超时。 */
|
||||
const directPut = axios.create({ timeout: 600_000, withCredentials: false })
|
||||
@@ -43,10 +46,15 @@ export async function requestTutorialPresign(fileName: string, version = ''): Pr
|
||||
}
|
||||
|
||||
/** 第三步:直传完成后通知后端校验对象并写入记录(data.item 为新记录行)。 */
|
||||
export async function confirmTutorialPackage(objectKey: string, fileName: string, version = ''): Promise<TutorialPackageItem | null> {
|
||||
const { data } = await http.post<unknown>(TUTORIAL_CONFIRM_ENDPOINT, null, {
|
||||
params: { object_key: objectKey, file_name: fileName, version },
|
||||
})
|
||||
export async function confirmTutorialPackage(
|
||||
objectKey: string,
|
||||
fileName: string,
|
||||
version = '',
|
||||
fileKey = '',
|
||||
): Promise<TutorialPackageItem | null> {
|
||||
const params: Record<string, string> = { object_key: objectKey, file_name: fileName, version }
|
||||
if (fileKey) params.file_key = fileKey
|
||||
const { data } = await http.post<unknown>(TUTORIAL_CONFIRM_ENDPOINT, null, { params })
|
||||
return parseTutorialPackageUpload(data)
|
||||
}
|
||||
|
||||
@@ -68,6 +76,11 @@ export async function uploadTutorialPackage(
|
||||
version = '',
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<TutorialPackageItem | null> {
|
||||
if (file.size > CHUNK_UPLOAD_THRESHOLD) {
|
||||
const uploaded = await uploadFileInChunks(file, fileName, onProgress)
|
||||
const fileKey = String(uploaded.fileKey ?? uploaded.file_key ?? '')
|
||||
return confirmTutorialPackage(String(uploaded.objectKey ?? ''), fileName, version, fileKey)
|
||||
}
|
||||
const target = await requestTutorialPresign(fileName, version)
|
||||
await directPut.put(target.uploadUrl, file, {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** 软件版本列表加载适配(任务 127):GET /api/admin/versions。 */
|
||||
import axios from 'axios'
|
||||
import { http, unwrap } from '@/api/http'
|
||||
import { CHUNK_UPLOAD_THRESHOLD, uploadFileInChunks } from '@/api/chunk-upload'
|
||||
import { parseSoftwareVersionList, parseSoftwareVersionUpload } from './version-model.ts'
|
||||
import type { SoftwareVersionItem, SoftwareVersionList } from './version-dto.ts'
|
||||
|
||||
@@ -9,6 +10,8 @@ export const SOFTWARE_VERSION_UPLOAD_ENDPOINT = '/api/admin/version'
|
||||
export const SOFTWARE_VERSION_PRESIGN_ENDPOINT = `${SOFTWARE_VERSION_UPLOAD_ENDPOINT}/presign`
|
||||
export const SOFTWARE_VERSION_CONFIRM_ENDPOINT = `${SOFTWARE_VERSION_UPLOAD_ENDPOINT}/confirm`
|
||||
export const SOFTWARE_VERSION_DELETE_ENDPOINT = `${SOFTWARE_VERSION_UPLOAD_ENDPOINT}/delete`
|
||||
/** 大档分片通道(AC-11):>8MB 的安装包走这里,不再一次性 presign PUT。 */
|
||||
export const SOFTWARE_VERSION_CHUNK_ENDPOINT = '/api/files/chunk'
|
||||
|
||||
/** MinIO 直传专用实例:不带 cookie、不挂 401 跳登录拦截器(预签名过期/签名失败不能误判会话过期);大 zip 给足超时。 */
|
||||
const directPut = axios.create({ timeout: 600_000, withCredentials: false })
|
||||
@@ -45,9 +48,14 @@ export async function requestSoftwareVersionPresign(version: string): Promise<So
|
||||
}
|
||||
}
|
||||
|
||||
/** 第三步:直传完成后通知后端校验对象并写入版本记录(data.item 为新版本行)。 */
|
||||
export async function confirmSoftwareVersion(version: string): Promise<SoftwareVersionItem | null> {
|
||||
const { data } = await http.post<unknown>(SOFTWARE_VERSION_CONFIRM_ENDPOINT, null, { params: { version } })
|
||||
/**
|
||||
* 第三步:上传完成后通知后端校验并写入版本记录(data.item 为新版本行)。
|
||||
* 分片通道把拼装件留在 Java 临时目录,服务端按 file_key 搬进 client 桶后再落库。
|
||||
*/
|
||||
export async function confirmSoftwareVersion(version: string, fileKey = ''): Promise<SoftwareVersionItem | null> {
|
||||
const params: Record<string, string> = { version }
|
||||
if (fileKey) params.file_key = fileKey
|
||||
const { data } = await http.post<unknown>(SOFTWARE_VERSION_CONFIRM_ENDPOINT, null, { params })
|
||||
return parseSoftwareVersionUpload(data)
|
||||
}
|
||||
|
||||
@@ -69,6 +77,12 @@ export async function uploadSoftwareVersion(
|
||||
_filename = '',
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<SoftwareVersionUploadResult> {
|
||||
if (file.size > CHUNK_UPLOAD_THRESHOLD) {
|
||||
const uploaded = await uploadFileInChunks(file, `${version}.zip`, onProgress)
|
||||
const fileKey = String(uploaded.fileKey ?? uploaded.file_key ?? '')
|
||||
const item = await confirmSoftwareVersion(version, fileKey)
|
||||
return { version, fileUrl: item?.fileUrl || String(uploaded.url ?? ''), item }
|
||||
}
|
||||
const target = await requestSoftwareVersionPresign(version)
|
||||
await directPut.put(target.uploadUrl, file, {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
|
||||
Reference in New Issue
Block a user