Browse Source

[ui-storagebrowser] adds available space check in chunk upload (#3931)

Ram Prasad Agarwal 10 months ago
parent
commit
48b087db91

+ 1 - 0
desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts

@@ -35,6 +35,7 @@ export const COPY_API_URL = '/api/v1/storage/copy/';
 export const BULK_COPY_API_URL = '/api/v1/storage/copy/bulk/';
 export const MOVE_API_URL = '/api/v1/storage/move/';
 export const BULK_MOVE_API_URL = '/api/v1/storage/move/bulk/';
+export const UPLOAD_AVAILABLE_SPACE_URL = '/api/v1/taskserver/upload/available_space/';
 
 export interface ApiFileSystem {
   file_system: string;

+ 15 - 0
desktop/core/src/desktop/js/utils/hooks/useFileUpload/useChunkUpload.ts

@@ -35,6 +35,8 @@ import {
   UploadChunkItem,
   UploadItem
 } from './util';
+import { get } from '../../../api/utils';
+import { UPLOAD_AVAILABLE_SPACE_URL } from '../../../reactComponents/FileChooser/api';
 
 interface UseUploadQueueResponse {
   addFiles: (item: UploadItem[]) => void;
@@ -134,7 +136,20 @@ const useChunkUpload = ({
     });
   };
 
+  const checkAvailableSpace = async (fileSize: number) => {
+    const { upload_available_space: availableSpace } = await get<{
+      upload_available_space: number;
+    }>(UPLOAD_AVAILABLE_SPACE_URL);
+    return availableSpace >= fileSize;
+  };
+
   const uploadItem = async (item: UploadItem) => {
+    const isSpaceAvailable = await checkAvailableSpace(item.file.size);
+    if (!isSpaceAvailable) {
+      onStatusUpdate(item, FileUploadStatus.Failed);
+      return Promise.resolve();
+    }
+
     onStatusUpdate(item, FileUploadStatus.Uploading);
     const chunks = getTotalChunk(item.file.size, chunkSize);
     if (chunks === 1) {