🐛 修复上传阶段状态与重试进度
补齐预签名和分片上传的初始化、上传、确认、成功与失败状态回调,使用实际上传对象的进度字节避免 ZIP 选中文件计数失真,并在新提交前清理旧错误状态。 - 空提交校验不再进入 uploading 状态,失败保留文件以便重试 - 完成架构检查、类型检查和生产构建验证
This commit is contained in:
1 parent
84ddf92b20
commit
43ebc8c1b2
4 files changed
+32
-14
No files matched your search
@@ -37,6 +37,7 @@ type PresignedUploadNotifier = (message: string, type: AlertType) => void
|
||||
type UsePresignedUploadOptions = {
|
||||
getMaxFileSize?: () => number
|
||||
notify?: PresignedUploadNotifier
|
||||
onStatus?: (status: PresignUploadStatus) => void
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +67,7 @@ export function usePresignedUpload(options: UsePresignedUploadOptions = {}) {
|
||||
const notify: PresignedUploadNotifier = (message, type) => {
|
||||
options.notify?.(message, type)
|
||||
}
|
||||
const onStatus = options.onStatus
|
||||
|
||||
/**
|
||||
* 文件大小验证
|
||||
@@ -110,6 +112,7 @@ export function usePresignedUpload(options: UsePresignedUploadOptions = {}) {
|
||||
*/
|
||||
const handleUploadError = (error: unknown): void => {
|
||||
presignStatus.value = PRESIGN_UPLOAD_STATUS.ERROR
|
||||
onStatus?.(PRESIGN_UPLOAD_STATUS.ERROR)
|
||||
const status = (error as ErrorWithResponse)?.response?.status
|
||||
const fallback =
|
||||
status === 404
|
||||
@@ -131,6 +134,7 @@ export function usePresignedUpload(options: UsePresignedUploadOptions = {}) {
|
||||
): Promise<PresignInitResponse | null> => {
|
||||
try {
|
||||
presignStatus.value = PRESIGN_UPLOAD_STATUS.INITIALIZING
|
||||
onStatus?.(PRESIGN_UPLOAD_STATUS.INITIALIZING)
|
||||
|
||||
const response = await PresignUploadService.initUpload({
|
||||
file_name: file.name,
|
||||
@@ -161,6 +165,7 @@ export function usePresignedUpload(options: UsePresignedUploadOptions = {}) {
|
||||
): Promise<string | null> => {
|
||||
try {
|
||||
presignStatus.value = PRESIGN_UPLOAD_STATUS.UPLOADING
|
||||
onStatus?.(PRESIGN_UPLOAD_STATUS.UPLOADING)
|
||||
|
||||
// 上传到 S3
|
||||
const progressHandler = createProgressHandler(options?.onProgress)
|
||||
@@ -176,6 +181,7 @@ export function usePresignedUpload(options: UsePresignedUploadOptions = {}) {
|
||||
|
||||
// 确认上传
|
||||
presignStatus.value = PRESIGN_UPLOAD_STATUS.CONFIRMING
|
||||
onStatus?.(PRESIGN_UPLOAD_STATUS.CONFIRMING)
|
||||
const confirmResponse = await PresignUploadService.confirmUpload(session.upload_id, {
|
||||
expire_value: options?.expireValue ?? DEFAULT_EXPIRE_VALUE,
|
||||
expire_style: options?.expireStyle ?? DEFAULT_EXPIRE_STYLE
|
||||
@@ -183,6 +189,7 @@ export function usePresignedUpload(options: UsePresignedUploadOptions = {}) {
|
||||
|
||||
if (confirmResponse.code === 200 && confirmResponse.detail?.code) {
|
||||
presignStatus.value = PRESIGN_UPLOAD_STATUS.SUCCESS
|
||||
onStatus?.(PRESIGN_UPLOAD_STATUS.SUCCESS)
|
||||
uploadedCode.value = String(confirmResponse.detail.code)
|
||||
// 确保进度为 100%
|
||||
uploadProgress.value = {
|
||||
@@ -211,6 +218,7 @@ export function usePresignedUpload(options: UsePresignedUploadOptions = {}) {
|
||||
): Promise<string | null> => {
|
||||
try {
|
||||
presignStatus.value = PRESIGN_UPLOAD_STATUS.UPLOADING
|
||||
onStatus?.(PRESIGN_UPLOAD_STATUS.UPLOADING)
|
||||
|
||||
const progressHandler = createProgressHandler(options?.onProgress)
|
||||
const uploadUrl =
|
||||
@@ -224,6 +232,7 @@ export function usePresignedUpload(options: UsePresignedUploadOptions = {}) {
|
||||
|
||||
if (response.code === 200 && response.detail?.code) {
|
||||
presignStatus.value = PRESIGN_UPLOAD_STATUS.SUCCESS
|
||||
onStatus?.(PRESIGN_UPLOAD_STATUS.SUCCESS)
|
||||
uploadedCode.value = String(response.detail.code)
|
||||
// 确保进度为 100%
|
||||
uploadProgress.value = {
|
||||
|
||||
Reference in new issue
Block a user