From f2750773f916c8866308c06d242199c949ccefeb Mon Sep 17 00:00:00 2001 From: Wren Date: Mon, 22 Sep 2025 11:48:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=80=BB=E8=BE=91=EF=BC=8C=E7=BB=9F=E4=B8=80JWT?= =?UTF-8?q?=E4=BB=A4=E7=89=8C=E5=A4=84=E7=90=86=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E8=AF=B7=E6=B1=82=E5=A4=B4=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB?= =?UTF-8?q?=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/files/files-upload.ts | 12 ++++++++---- app/routes/documents._index.tsx | 6 ++++-- app/routes/rules-files.tsx | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/api/files/files-upload.ts b/app/api/files/files-upload.ts index 75d5ed8..99d8d33 100644 --- a/app/api/files/files-upload.ts +++ b/app/api/files/files-upload.ts @@ -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 }); diff --git a/app/routes/documents._index.tsx b/app/routes/documents._index.tsx index 2ecf9ca..41a5f06 100644 --- a/app/routes/documents._index.tsx +++ b/app/routes/documents._index.tsx @@ -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) { diff --git a/app/routes/rules-files.tsx b/app/routes/rules-files.tsx index 32d8b6b..8285ada 100644 --- a/app/routes/rules-files.tsx +++ b/app/routes/rules-files.tsx @@ -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);