refactor: switch upload to new POST /api/upload with flat FormData
Replace the old nested upload_info JSON approach with flat
multipart fields (typeId, region, fileRole, createdBy, autoRun,
speed) matching the new leaudit-platform backend.
- uploadDocumentToServer: POST ${API_BASE_URL}/api/upload
- handleFileUpload: pass region from userInfo.area, derive speed
from priority enum, pass createdBy from JWT user_id
- UploadResult replaces FileUploadResponse with documentId/fileId
replacing the old nested result.id/result.file_name pattern
This commit is contained in:
+88
-119
@@ -171,26 +171,47 @@ export interface ContractStructureComparison {
|
|||||||
comparison_results?: Record<string, unknown>;
|
comparison_results?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件上传响应接口
|
// 文件上传响应接口(兼容旧前端)
|
||||||
export interface FileUploadResponse {
|
export interface UploadResult {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
result?: {
|
documentId: number;
|
||||||
id: number;
|
fileId: number;
|
||||||
file_name: string;
|
fileName: string;
|
||||||
file_size: number;
|
fileSize: number;
|
||||||
file_url: string;
|
typeId: number;
|
||||||
type_id: number;
|
region: string;
|
||||||
type_description: string;
|
processingStatus: string;
|
||||||
document_number: string | null;
|
duplicateUpload: boolean;
|
||||||
storage_type: string;
|
error?: string;
|
||||||
is_test_document: boolean;
|
}
|
||||||
remark: string | null;
|
|
||||||
background_processing: boolean;
|
// 旧接口上传响应(uploadContractTemplate / appendContractAttachments 仍在使用)
|
||||||
evaluation_level: string;
|
interface LegacyUploadResponse {
|
||||||
};
|
success: boolean;
|
||||||
|
result?: { id: number; file_name: string; file_size: number; [key: string]: unknown };
|
||||||
error: string | null;
|
error: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新后端上传响应
|
||||||
|
interface NewUploadResponse {
|
||||||
|
documentId: number;
|
||||||
|
internalDocumentNo: number;
|
||||||
|
versionGroupKey: string;
|
||||||
|
versionNo: number;
|
||||||
|
previousVersionId: number | null;
|
||||||
|
rootVersionId: number;
|
||||||
|
duplicateUpload: boolean;
|
||||||
|
fileId: number;
|
||||||
|
typeId: number;
|
||||||
|
typeCode: string;
|
||||||
|
region: string;
|
||||||
|
fileName: string;
|
||||||
|
ossUrl: string;
|
||||||
|
speed: string;
|
||||||
|
processingStatus: string;
|
||||||
|
autoRunTriggered: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将文件转换为二进制数据
|
* 将文件转换为二进制数据
|
||||||
*/
|
*/
|
||||||
@@ -237,7 +258,7 @@ export async function uploadContractTemplate(
|
|||||||
documentId: number,
|
documentId: number,
|
||||||
comparisonId?: number,
|
comparisonId?: number,
|
||||||
jwtToken?: string
|
jwtToken?: string
|
||||||
): Promise<{data: FileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
): Promise<{data: LegacyUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
||||||
try {
|
try {
|
||||||
console.log('【合同模板上传】开始上传模板:', { fileName: file.name, documentId, comparisonId });
|
console.log('【合同模板上传】开始上传模板:', { fileName: file.name, documentId, comparisonId });
|
||||||
|
|
||||||
@@ -313,7 +334,7 @@ export async function appendContractAttachments(
|
|||||||
isReprocess: boolean = true,
|
isReprocess: boolean = true,
|
||||||
remark?: string,
|
remark?: string,
|
||||||
token?: string
|
token?: string
|
||||||
): Promise<{data: FileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
): Promise<{data: LegacyUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
||||||
try {
|
try {
|
||||||
console.log('【合同附件追加】开始追加附件:', { documentId, fileCount: files.length, mergeMode });
|
console.log('【合同附件追加】开始追加附件:', { documentId, fileCount: files.length, mergeMode });
|
||||||
|
|
||||||
@@ -375,119 +396,67 @@ export async function uploadDocumentToServer(
|
|||||||
binaryData: ArrayBuffer,
|
binaryData: ArrayBuffer,
|
||||||
fileName: string,
|
fileName: string,
|
||||||
fileType: string,
|
fileType: string,
|
||||||
typeId: string | number,
|
typeId: number,
|
||||||
priority: string,
|
region: string = "default",
|
||||||
documentNumber?: string | null,
|
createdBy?: number,
|
||||||
remark?: string | null,
|
autoRun: boolean = true,
|
||||||
isTestDocument: boolean = false,
|
speed: string = "normal",
|
||||||
documentId?: number | null,
|
|
||||||
isReupload: boolean = false,
|
|
||||||
jwtToken?: string,
|
jwtToken?: string,
|
||||||
attachments?: File[],
|
): Promise<{ data: UploadResult } | { error: string; status?: number }> {
|
||||||
attributeType?: string
|
|
||||||
): Promise<{data: FileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
|
||||||
try {
|
try {
|
||||||
// console.log('【调试】开始上传文档:', { fileName, fileSize: binaryData.byteLength });
|
|
||||||
|
|
||||||
// 创建FormData对象
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
// 将二进制数据转换为Blob并添加到FormData
|
|
||||||
const blob = new Blob([binaryData], { type: fileType });
|
const blob = new Blob([binaryData], { type: fileType });
|
||||||
formData.append('file', blob, fileName);
|
formData.append("file", blob, fileName);
|
||||||
// console.log('【调试】Blob已创建,文件大小:', blob.size);
|
formData.append("typeId", String(typeId));
|
||||||
|
formData.append("region", region);
|
||||||
|
formData.append("fileRole", "primary");
|
||||||
|
if (createdBy !== undefined) {
|
||||||
|
formData.append("createdBy", String(createdBy));
|
||||||
|
}
|
||||||
|
formData.append("autoRun", String(autoRun));
|
||||||
|
formData.append("speed", speed);
|
||||||
|
|
||||||
// 将信息添加到一个JSON对象中
|
const headers: Record<string, string> = {
|
||||||
const uploadInfo = {
|
"X-File-Name": encodeURIComponent(fileName),
|
||||||
type_id: Number(typeId),
|
|
||||||
evaluation_level: priority,
|
|
||||||
document_number: documentNumber || null,
|
|
||||||
remark: remark || null,
|
|
||||||
is_test_document: isTestDocument,
|
|
||||||
document_id: documentId || null,
|
|
||||||
is_reupload: isReupload,
|
|
||||||
attribute_type: attributeType || null
|
|
||||||
};
|
};
|
||||||
|
if (jwtToken) {
|
||||||
// 添加JSON字符串到FormData
|
headers["Authorization"] = `Bearer ${jwtToken}`;
|
||||||
formData.append('upload_info', JSON.stringify(uploadInfo));
|
|
||||||
// console.log('【调试】FormData准备完成:', JSON.stringify(uploadInfo));
|
|
||||||
|
|
||||||
// 如果提供了附件(仅当后端支持首传合并时使用),按照后端规范追加到 FormData
|
|
||||||
if (attachments && attachments.length > 0) {
|
|
||||||
attachments.forEach(att => {
|
|
||||||
formData.append('attachments', att);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据是否有documentId决定使用哪个接口
|
const response = await axios.post(`${API_BASE_URL}/api/upload`, formData, { headers });
|
||||||
// 首传合并:无论是否有附件,都应走 /upload;
|
const body = response.data;
|
||||||
// 仅当要上传“合同模板”时,使用独立的 uploadContractTemplate 接口(不在本函数中处理)。
|
|
||||||
const uploadEndpoint = '/upload';
|
|
||||||
const uploadUrl = UPLOAD_URL + uploadEndpoint;
|
|
||||||
// console.log('【调试】准备发送请求到服务器:', uploadUrl);
|
|
||||||
|
|
||||||
// 发送请求
|
// Result<DocumentUploadVO> envelope
|
||||||
// const response = await axios.post(`${API_BASE_URL}/admin/documents/upload`, ...
|
const uploadData: NewUploadResponse | undefined = body?.data;
|
||||||
try {
|
if (!uploadData || !uploadData.documentId) {
|
||||||
// console.log('【调试】开始axios请求...');
|
return { error: body?.message || "上传响应解析失败", status: response.status };
|
||||||
|
|
||||||
// 构建请求头,只在有JWT token时添加Authorization
|
|
||||||
const headers: Record<string, string> = {
|
|
||||||
'X-File-Name': encodeURIComponent(fileName)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (jwtToken) {
|
|
||||||
headers['Authorization'] = `Bearer ${jwtToken}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.post(uploadUrl, formData, {
|
|
||||||
headers
|
|
||||||
});
|
|
||||||
|
|
||||||
// console.log('【调试】收到服务器响应:', { status: response.status, statusText: response.statusText });
|
|
||||||
|
|
||||||
const responseData = response.data;
|
|
||||||
// console.log('【上传调试】服务器原始JSON响应:', responseData);
|
|
||||||
// console.log('【上传调试】响应类型:', typeof responseData);
|
|
||||||
// console.log('【上传调试】响应keys:', Object.keys(responseData));
|
|
||||||
|
|
||||||
const extractedData = extractApiData<FileUploadResponse>(responseData);
|
|
||||||
// console.log('【上传调试】提取后的数据:', extractedData);
|
|
||||||
// console.log('【上传调试】提取数据详情:', {
|
|
||||||
// hasData: !!extractedData,
|
|
||||||
// success: extractedData?.success,
|
|
||||||
// hasResult: !!extractedData?.result,
|
|
||||||
// error: extractedData?.error
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (!extractedData) {
|
|
||||||
console.error('【调试】无法提取数据,原始响应:', JSON.stringify(responseData));
|
|
||||||
return { error: '处理上传响应失败', status: 500 };
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log('【调试】上传成功,返回数据');
|
|
||||||
return { data: extractedData };
|
|
||||||
} catch (axiosError) {
|
|
||||||
console.error('【调试】axios请求失败:', axiosError);
|
|
||||||
if (axios.isAxiosError(axiosError)) {
|
|
||||||
const errorText = axiosError.response?.data || axiosError.message;
|
|
||||||
return {
|
|
||||||
error: `上传失败: ${axiosError.response?.status || 500} ${axiosError.response?.statusText || ''} - ${errorText}`,
|
|
||||||
status: axiosError.response?.status || 500
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
error: `axios请求错误: ${axiosError instanceof Error ? axiosError.message : '未知错误'}`,
|
|
||||||
status: 500
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error('【调试】上传过程中发生错误:', error);
|
|
||||||
return {
|
return {
|
||||||
error: error instanceof Error ? error.message : '上传失败',
|
data: {
|
||||||
status: 500
|
success: true,
|
||||||
|
documentId: uploadData.documentId,
|
||||||
|
fileId: uploadData.fileId,
|
||||||
|
fileName: uploadData.fileName,
|
||||||
|
fileSize: binaryData.byteLength,
|
||||||
|
typeId: uploadData.typeId,
|
||||||
|
region: uploadData.region,
|
||||||
|
processingStatus: uploadData.processingStatus,
|
||||||
|
duplicateUpload: uploadData.duplicateUpload,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
} catch (axiosError) {
|
||||||
|
console.error("上传文档失败:", axiosError);
|
||||||
|
if (axios.isAxiosError(axiosError)) {
|
||||||
|
const serverMessage =
|
||||||
|
(axiosError.response?.data as any)?.message ||
|
||||||
|
(axiosError.response?.data as any)?.msg;
|
||||||
|
return {
|
||||||
|
error: serverMessage || `上传失败 (HTTP ${axiosError.response?.status || "unknown"})`,
|
||||||
|
status: axiosError.response?.status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { error: axiosError instanceof Error ? axiosError.message : "上传失败" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+46
-104
@@ -21,7 +21,7 @@ import {
|
|||||||
checkDocumentDuplicate,
|
checkDocumentDuplicate,
|
||||||
type Document,
|
type Document,
|
||||||
type DocumentType,
|
type DocumentType,
|
||||||
type FileUploadResponse,
|
type UploadResult,
|
||||||
DocumentStatus
|
DocumentStatus
|
||||||
} from "~/api/files/files-upload";
|
} from "~/api/files/files-upload";
|
||||||
import { updateDocumentAuditStatus } from "~/api/evaluation_points/rules-files";
|
import { updateDocumentAuditStatus } from "~/api/evaluation_points/rules-files";
|
||||||
@@ -126,52 +126,30 @@ async function handleFileUpload(
|
|||||||
fileType: string,
|
fileType: string,
|
||||||
documentType: FileType,
|
documentType: FileType,
|
||||||
priority: Priority,
|
priority: Priority,
|
||||||
documentNumber: string | null,
|
region: string,
|
||||||
remark: string | null,
|
createdBy?: number,
|
||||||
isTestDocument: boolean,
|
|
||||||
documentId?: number | null,
|
|
||||||
isReupload: boolean = false,
|
|
||||||
jwtToken?: string,
|
jwtToken?: string,
|
||||||
attachments?: File[],
|
): Promise<UploadResult> {
|
||||||
attributeType?: string
|
const speed = priority === Priority.NORMAL ? "normal" : "urgent";
|
||||||
): Promise<FileUploadResponse> {
|
|
||||||
// console.log('【handleFileUpload】开始上传:', {
|
|
||||||
// fileName,
|
|
||||||
// fileSize: binaryData.byteLength,
|
|
||||||
// documentType,
|
|
||||||
// hasAttachments: !!(attachments && attachments.length > 0),
|
|
||||||
// attachmentCount: attachments?.length || 0
|
|
||||||
// });
|
|
||||||
|
|
||||||
const response = await uploadDocumentToServer(
|
const response = await uploadDocumentToServer(
|
||||||
binaryData,
|
binaryData,
|
||||||
fileName,
|
fileName,
|
||||||
fileType,
|
fileType,
|
||||||
documentType,
|
Number(documentType),
|
||||||
priority,
|
region,
|
||||||
documentNumber,
|
createdBy,
|
||||||
remark,
|
true,
|
||||||
isTestDocument,
|
speed,
|
||||||
documentId,
|
|
||||||
isReupload,
|
|
||||||
jwtToken,
|
jwtToken,
|
||||||
attachments,
|
|
||||||
attributeType
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// console.log('【handleFileUpload】uploadDocumentToServer返回:', {
|
if ("error" in response || !response.data) {
|
||||||
// hasError: !!response.error,
|
const errMsg = "error" in response ? response.error : "上传响应为空";
|
||||||
// hasData: !!response.data,
|
console.error("上传失败:", errMsg);
|
||||||
// error: response.error,
|
throw new Error(errMsg || "上传失败");
|
||||||
// dataKeys: response.data ? Object.keys(response.data) : []
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (response.error || !response.data) {
|
|
||||||
console.error('【handleFileUpload】上传失败:', response.error);
|
|
||||||
throw new Error(response.error || '上传失败');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('【handleFileUpload】返回数据:', response.data);
|
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1184,39 +1162,20 @@ export default function FilesUpload() {
|
|||||||
// 转二进制
|
// 转二进制
|
||||||
const binaryData = await uploadFileToBinary(mainFile);
|
const binaryData = await uploadFileToBinary(mainFile);
|
||||||
|
|
||||||
// 首传:将附件通过 attachments 一起带上
|
// 首传
|
||||||
|
const region = (loaderData.userInfo?.area as string) || "default";
|
||||||
|
const createdBy = loaderData.userInfo?.user_id as number | undefined;
|
||||||
const uploadResp = await handleFileUpload(
|
const uploadResp = await handleFileUpload(
|
||||||
binaryData,
|
binaryData, mainFile.name, mainFile.type,
|
||||||
mainFile.name,
|
fileType as FileType, priority,
|
||||||
mainFile.type,
|
region, createdBy, loaderData.frontendJWT || undefined,
|
||||||
fileType as FileType,
|
|
||||||
priority,
|
|
||||||
documentNumber || null,
|
|
||||||
remark || null,
|
|
||||||
isTestDocument,
|
|
||||||
null,
|
|
||||||
false,
|
|
||||||
loaderData.frontendJWT || undefined,
|
|
||||||
attachmentFiles,
|
|
||||||
attributeType
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// console.log('【合同上传】服务器响应数据:', uploadResp);
|
|
||||||
// console.log('【合同上传】响应详情:', {
|
|
||||||
// success: uploadResp.success,
|
|
||||||
// hasResult: !!uploadResp.result,
|
|
||||||
// error: uploadResp.error,
|
|
||||||
// fullResponse: JSON.stringify(uploadResp)
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (!uploadResp.success) {
|
if (!uploadResp.success) {
|
||||||
throw new Error(uploadResp.error || '上传失败,服务器返回success=false');
|
throw new Error(uploadResp.error || "上传失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uploadResp.result) {
|
const documentId = uploadResp.documentId;
|
||||||
throw new Error('主文件上传失败:服务器未返回文档信息');
|
|
||||||
}
|
|
||||||
const documentId = uploadResp.result.id;
|
|
||||||
|
|
||||||
// 可选:模板上传
|
// 可选:模板上传
|
||||||
if (templateFiles && templateFiles.length > 0) {
|
if (templateFiles && templateFiles.length > 0) {
|
||||||
@@ -1240,14 +1199,13 @@ export default function FilesUpload() {
|
|||||||
setUploadProgress(100);
|
setUploadProgress(100);
|
||||||
setUploadSpeed('完成');
|
setUploadSpeed('完成');
|
||||||
|
|
||||||
toastService.success('上传成功');
|
toastService.success("上传成功");
|
||||||
|
|
||||||
// 构造已上传文件并进入处理流程(保持与旧逻辑一致,点亮步骤条)
|
|
||||||
const uploadedFiles: UploadedFile[] = [
|
const uploadedFiles: UploadedFile[] = [
|
||||||
{
|
{
|
||||||
id: uploadResp.result.id,
|
id: uploadResp.documentId,
|
||||||
name: uploadResp.result.file_name,
|
name: uploadResp.fileName,
|
||||||
size: uploadResp.result.file_size,
|
size: uploadResp.fileSize,
|
||||||
type: mainFile.type,
|
type: mainFile.type,
|
||||||
fileType: fileType as FileType,
|
fileType: fileType as FileType,
|
||||||
priority,
|
priority,
|
||||||
@@ -1499,15 +1457,10 @@ export default function FilesUpload() {
|
|||||||
throw new Error(`文件 ${file.name} 转换失败: ${binaryError instanceof Error ? binaryError.message : '未知错误'}`);
|
throw new Error(`文件 ${file.name} 转换失败: ${binaryError instanceof Error ? binaryError.message : '未知错误'}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let response: FileUploadResponse;
|
let response: UploadResult;
|
||||||
// console.log(`【调试-startUpload】开始上传文件 ${file.name} 到服务器,文件类型: ${fileType}`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 上传文件
|
|
||||||
// 检查组件是否已卸载
|
|
||||||
if (!isMountedRef.current) {
|
if (!isMountedRef.current) {
|
||||||
console.error('【调试-startUpload】组件已卸载,取消上传');
|
return { success: false, error: "组件已卸载", documentId: 0, fileId: 0, fileName: "", fileSize: 0, typeId: 0, region: "", processingStatus: "", duplicateUpload: false } as UploadResult;
|
||||||
return { success: false, error: '组件已卸载' } as FileUploadResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(`【调试-startUpload】准备上传文件 ${file.name} 到服务器`);
|
// console.log(`【调试-startUpload】准备上传文件 ${file.name} 到服务器`);
|
||||||
@@ -1544,26 +1497,18 @@ export default function FilesUpload() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 使用Promise.race添加超时处理
|
// 使用Promise.race添加超时处理
|
||||||
|
const region = (loaderData.userInfo?.area as string) || "default";
|
||||||
|
const createdBy = loaderData.userInfo?.user_id as number | undefined;
|
||||||
const uploadPromise = handleFileUpload(
|
const uploadPromise = handleFileUpload(
|
||||||
binaryData,
|
binaryData, file.name, file.type,
|
||||||
file.name,
|
fileType as FileType, priority,
|
||||||
file.type,
|
region, createdBy, loaderData.frontendJWT || undefined,
|
||||||
fileType as FileType,
|
|
||||||
priority,
|
|
||||||
documentNumber || null,
|
|
||||||
remark || null,
|
|
||||||
isTestDocument,
|
|
||||||
temp_n > 1 ? firstFileDocumentId : null, // 第二个文件及以后使用第一个文件的document_id
|
|
||||||
false,
|
|
||||||
loaderData.frontendJWT || undefined,
|
|
||||||
undefined,
|
|
||||||
attributeType
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const timeoutPromise = new Promise<FileUploadResponse>((_, reject) => {
|
const timeoutPromise = new Promise<UploadResult>((_, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reject(new Error('上传超时'));
|
reject(new Error("上传超时"));
|
||||||
}, 600000); // 10分钟超时
|
}, 600000);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 并行执行上传和进度更新
|
// 并行执行上传和进度更新
|
||||||
@@ -1584,16 +1529,15 @@ export default function FilesUpload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查上传结果
|
// 检查上传结果
|
||||||
if (!uploadResult.success || !uploadResult.result) {
|
if (!uploadResult.success) {
|
||||||
throw new Error(uploadResult.error || '上传失败');
|
throw new Error(uploadResult.error || "上传失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
response = uploadResult;
|
response = uploadResult;
|
||||||
|
|
||||||
// 保存第一个文件的document_id,用于后续附件上传
|
// 保存第一个文件的 documentId
|
||||||
if (temp_n === 1 && response.result?.id) {
|
if (temp_n === 1 && response.documentId) {
|
||||||
firstFileDocumentId = response.result.id;
|
firstFileDocumentId = response.documentId;
|
||||||
console.log('【调试-startUpload】保存第一个文件的document_id:', firstFileDocumentId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(`【调试-startUpload】文件 ${file.name} 上传响应:`, response);
|
// console.log(`【调试-startUpload】文件 ${file.name} 上传响应:`, response);
|
||||||
@@ -1608,19 +1552,17 @@ export default function FilesUpload() {
|
|||||||
throw new Error(`文件 ${file.name} 上传失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
throw new Error(`文件 ${file.name} 上传失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.success || !response.result) {
|
if (!response.success) {
|
||||||
console.error(`【调试-startUpload】文件 ${file.name} 上传失败:`, response.error);
|
console.error(`上传文件 ${file.name} 失败:`, response.error);
|
||||||
throw new Error(response.error || `文件 ${file.name} 上传失败`);
|
throw new Error(response.error || `文件 ${file.name} 上传失败`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新已上传大小
|
|
||||||
uploadedSize += file.size;
|
uploadedSize += file.size;
|
||||||
|
|
||||||
// 创建新的文件对象
|
|
||||||
const newFile: UploadedFile = {
|
const newFile: UploadedFile = {
|
||||||
id: response.result.id,
|
id: response.documentId,
|
||||||
name: response.result.file_name,
|
name: response.fileName,
|
||||||
size: response.result.file_size,
|
size: response.fileSize,
|
||||||
type: file.type,
|
type: file.type,
|
||||||
fileType: fileType as FileType,
|
fileType: fileType as FileType,
|
||||||
priority,
|
priority,
|
||||||
|
|||||||
Reference in New Issue
Block a user