Skip to content

Commit

Permalink
[ui-storagebrowser] adds available space check in chunk upload (#3931)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramprasadagarwal authored and agl29 committed Jan 13, 2025
1 parent 46fb172 commit 995d803
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 995d803

Please sign in to comment.