优化文件上传逻辑,统一JWT令牌处理方式,简化请求头设置,提升代码可读性。
This commit is contained in:
@@ -357,12 +357,16 @@ export async function uploadDocumentToServer(
|
|||||||
// const response = await fetch(`${API_BASE_URL}/admin/documents/upload`, {
|
// const response = await fetch(`${API_BASE_URL}/admin/documents/upload`, {
|
||||||
try {
|
try {
|
||||||
// console.log('【调试】开始fetch请求...');
|
// 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, {
|
const response = await fetch(uploadUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers,
|
||||||
'X-File-Name': encodeURIComponent(fileName),
|
|
||||||
'Authorization': `Bearer ${jwtToken || ''}`
|
|
||||||
},
|
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -788,13 +788,14 @@ export default function DocumentsIndex() {
|
|||||||
try {
|
try {
|
||||||
setAttachmentUploading(true);
|
setAttachmentUploading(true);
|
||||||
|
|
||||||
|
const jwtToken = (loaderData.frontendJWT as string | undefined) || (loaderData.userInfo?.frontend_jwt as unknown as string | undefined);
|
||||||
const result = await appendContractAttachments(
|
const result = await appendContractAttachments(
|
||||||
selectedDocumentId,
|
selectedDocumentId,
|
||||||
attachmentFiles,
|
attachmentFiles,
|
||||||
attachmentMergeMode,
|
attachmentMergeMode,
|
||||||
true, // isReprocess
|
true, // isReprocess
|
||||||
attachmentRemark || undefined,
|
attachmentRemark || undefined,
|
||||||
loaderData.frontendJWT as string | undefined
|
jwtToken
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
@@ -862,11 +863,12 @@ export default function DocumentsIndex() {
|
|||||||
try {
|
try {
|
||||||
setTemplateUploading(true);
|
setTemplateUploading(true);
|
||||||
|
|
||||||
|
const jwtToken = (loaderData.frontendJWT as string | undefined) || (loaderData.userInfo?.frontend_jwt as unknown as string | undefined);
|
||||||
const result = await uploadContractTemplate(
|
const result = await uploadContractTemplate(
|
||||||
templateFile,
|
templateFile,
|
||||||
selectedDocumentId,
|
selectedDocumentId,
|
||||||
undefined, // comparisonId
|
undefined, // comparisonId
|
||||||
loaderData.frontendJWT as string | undefined
|
jwtToken
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
|
|||||||
@@ -512,13 +512,14 @@ export default function RulesFiles() {
|
|||||||
try {
|
try {
|
||||||
setAttachmentUploading(true);
|
setAttachmentUploading(true);
|
||||||
const docId = parseInt(selectedDocumentId, 10);
|
const docId = parseInt(selectedDocumentId, 10);
|
||||||
|
const jwtToken = (frontendJWT as string | undefined) || (userInfo?.frontend_jwt as unknown as string | undefined);
|
||||||
const result = await appendContractAttachments(
|
const result = await appendContractAttachments(
|
||||||
docId,
|
docId,
|
||||||
attachmentFiles,
|
attachmentFiles,
|
||||||
attachmentMergeMode,
|
attachmentMergeMode,
|
||||||
true,
|
true,
|
||||||
attachmentRemark || undefined,
|
attachmentRemark || undefined,
|
||||||
frontendJWT as string | undefined
|
jwtToken
|
||||||
);
|
);
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
throw new Error(result.error);
|
throw new Error(result.error);
|
||||||
|
|||||||
Reference in New Issue
Block a user