优化文件上传逻辑,统一JWT令牌处理方式,简化请求头设置,提升代码可读性。

This commit is contained in:
2025-09-22 11:48:12 +08:00
parent aec2e1fca2
commit f2750773f9
3 changed files with 14 additions and 7 deletions
+8 -4
View File
@@ -357,12 +357,16 @@ export async function uploadDocumentToServer(
// const response = await fetch(`${API_BASE_URL}/admin/documents/upload`, {
try {
// console.log('【调试】开始fetch请求...');
const headers: HeadersInit = {
'X-File-Name': encodeURIComponent(fileName),
'Accept': 'application/json'
};
if (jwtToken) {
headers['Authorization'] = `Bearer ${jwtToken}`;
}
const response = await fetch(uploadUrl, {
method: 'POST',
headers: {
'X-File-Name': encodeURIComponent(fileName),
'Authorization': `Bearer ${jwtToken || ''}`
},
headers,
body: formData
});
+4 -2
View File
@@ -788,13 +788,14 @@ export default function DocumentsIndex() {
try {
setAttachmentUploading(true);
const jwtToken = (loaderData.frontendJWT as string | undefined) || (loaderData.userInfo?.frontend_jwt as unknown as string | undefined);
const result = await appendContractAttachments(
selectedDocumentId,
attachmentFiles,
attachmentMergeMode,
true, // isReprocess
attachmentRemark || undefined,
loaderData.frontendJWT as string | undefined
jwtToken
);
if (result.error) {
@@ -862,11 +863,12 @@ export default function DocumentsIndex() {
try {
setTemplateUploading(true);
const jwtToken = (loaderData.frontendJWT as string | undefined) || (loaderData.userInfo?.frontend_jwt as unknown as string | undefined);
const result = await uploadContractTemplate(
templateFile,
selectedDocumentId,
undefined, // comparisonId
loaderData.frontendJWT as string | undefined
jwtToken
);
if (result.error) {
+2 -1
View File
@@ -512,13 +512,14 @@ export default function RulesFiles() {
try {
setAttachmentUploading(true);
const docId = parseInt(selectedDocumentId, 10);
const jwtToken = (frontendJWT as string | undefined) || (userInfo?.frontend_jwt as unknown as string | undefined);
const result = await appendContractAttachments(
docId,
attachmentFiles,
attachmentMergeMode,
true,
attachmentRemark || undefined,
frontendJWT as string | undefined
jwtToken
);
if (result.error) {
throw new Error(result.error);