优化文件上传逻辑,统一JWT令牌处理方式,简化请求头设置,提升代码可读性。
This commit is contained in:
@@ -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
|
||||
});
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user