فهرست منبع

[ui-sb] moves the destination_path from FormData to query param (#4217)

Ram Prasad Agarwal 3 ماه پیش
والد
کامیت
ecc3a7a799

+ 10 - 8
desktop/core/src/desktop/js/utils/hooks/useFileUpload/useRegularUpload.test.tsx

@@ -107,15 +107,17 @@ describe('useRegularUpload', () => {
 
 
     const mockFormData = new FormData();
     const mockFormData = new FormData();
     mockFormData.append('file', mockFile.file);
     mockFormData.append('file', mockFile.file);
-    mockFormData.append('destination_path', mockFile.filePath);
 
 
-    expect(mockSave).toHaveBeenCalledWith(
-      mockFormData,
-      expect.objectContaining({
-        onSuccess: expect.any(Function),
-        onError: expect.any(Function)
-      })
-    );
+    expect(mockSave).toHaveBeenCalledWith(mockFormData, {
+      onSuccess: expect.any(Function),
+      onError: expect.any(Function),
+      postOptions: {
+        onUploadProgress: expect.any(Function),
+        params: {
+          destination_path: mockFile.filePath
+        }
+      }
+    });
     expect(mockUpdateFileVariables).toHaveBeenCalledWith(mockFile.uuid, {
     expect(mockUpdateFileVariables).toHaveBeenCalledWith(mockFile.uuid, {
       status: FileStatus.Uploading
       status: FileStatus.Uploading
     });
     });

+ 7 - 5
desktop/core/src/desktop/js/utils/hooks/useFileUpload/useRegularUpload.ts

@@ -21,13 +21,13 @@ import useSaveData from '../useSaveData/useSaveData';
 import { getItemProgress } from './utils';
 import { getItemProgress } from './utils';
 import { RegularFile, FileVariables, FileStatus } from './types';
 import { RegularFile, FileVariables, FileStatus } from './types';
 
 
-interface UseUploadQueueResponse {
-  addFiles: (item: RegularFile[]) => void;
+interface UseRegularUploadResponse {
+  addFiles: (items: RegularFile[], overwrite?: boolean) => void;
   cancelFile: (uuid: RegularFile['uuid']) => void;
   cancelFile: (uuid: RegularFile['uuid']) => void;
   isLoading: boolean;
   isLoading: boolean;
 }
 }
 
 
-interface UploadQueueOptions {
+interface UseRegularUploadProps {
   concurrentProcess?: number;
   concurrentProcess?: number;
   updateFileVariables: (item: RegularFile['uuid'], variables: FileVariables) => void;
   updateFileVariables: (item: RegularFile['uuid'], variables: FileVariables) => void;
   onComplete: () => void;
   onComplete: () => void;
@@ -37,7 +37,7 @@ const useRegularUpload = ({
   concurrentProcess = DEFAULT_CONCURRENT_MAX_CONNECTIONS,
   concurrentProcess = DEFAULT_CONCURRENT_MAX_CONNECTIONS,
   updateFileVariables,
   updateFileVariables,
   onComplete
   onComplete
-}: UploadQueueOptions): UseUploadQueueResponse => {
+}: UseRegularUploadProps): UseRegularUploadResponse => {
   const { save } = useSaveData(UPLOAD_FILE_URL);
   const { save } = useSaveData(UPLOAD_FILE_URL);
 
 
   const processRegularFile = async (item: RegularFile) => {
   const processRegularFile = async (item: RegularFile) => {
@@ -45,7 +45,6 @@ const useRegularUpload = ({
 
 
     const payload = new FormData();
     const payload = new FormData();
     payload.append('file', item.file);
     payload.append('file', item.file);
-    payload.append('destination_path', item.filePath);
 
 
     return save(payload, {
     return save(payload, {
       onSuccess: () => {
       onSuccess: () => {
@@ -55,6 +54,9 @@ const useRegularUpload = ({
         updateFileVariables(item.uuid, { status: FileStatus.Failed, error });
         updateFileVariables(item.uuid, { status: FileStatus.Failed, error });
       },
       },
       postOptions: {
       postOptions: {
+        params: {
+          destination_path: item.filePath
+        },
         onUploadProgress: progress => {
         onUploadProgress: progress => {
           const itemProgress = getItemProgress(progress);
           const itemProgress = getItemProgress(progress);
           updateFileVariables(item.uuid, { progress: itemProgress });
           updateFileVariables(item.uuid, { progress: itemProgress });