Skip to content

Commit

Permalink
[ui-storagebrowser] port APIs to public and fixes the chunk upload (#…
Browse files Browse the repository at this point in the history
…3967)

* [ui-storagebrowser] port APIs to public

* [ui-storagebrowser] fixes the chunk upload variables
  • Loading branch information
ramprasadagarwal authored Jan 23, 2025
1 parent f6cd307 commit bd8e80c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const StorageBrowserActions = ({

const downloadFile = () => {
huePubSub.publish('hue.global.info', { message: t('Downloading your file, Please wait...') });
location.href = `${DOWNLOAD_API_URL}${selectedFiles[0]?.path}`;
location.href = `${DOWNLOAD_API_URL}?path=${selectedFiles[0]?.path}`;
};

const onActionClick = (actionType: ActionType) => () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('StorageFilePage', () => {
});

const downloadLink = screen.getByRole('link', { name: 'Download' });
expect(downloadLink).toHaveAttribute('href', `${DOWNLOAD_API_URL}${mockFileStats.path}`);
expect(downloadLink).toHaveAttribute('href', `${DOWNLOAD_API_URL}?path=${mockFileStats.path}`);
});

it('should download a file when download button is clicked', async () => {
Expand All @@ -216,7 +216,7 @@ describe('StorageFilePage', () => {
});

const downloadLink = screen.getByRole('link', { name: 'Download' });
expect(downloadLink).toHaveAttribute('href', `${DOWNLOAD_API_URL}${mockFileStats.path}`);
expect(downloadLink).toHaveAttribute('href', `${DOWNLOAD_API_URL}?path=${mockFileStats.path}`);
});

it('should not render the download button when show_download_button is false', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ const StorageFilePage = ({ fileName, fileStats, onReload }: StorageFilePageProps
huePubSub.publish('hue.global.info', { message: t('Downloading your file, Please wait...') });
};

const filePreviewUrl = `${DOWNLOAD_API_URL}${fileStats.path}?disposition=inline`;
const fileDownloadUrl = `${DOWNLOAD_API_URL}?path=${fileStats.path}`;
const filePreviewUrl = `${fileDownloadUrl}&&disposition=inline`;

const isEditingEnabled =
!isEditing &&
Expand Down Expand Up @@ -192,7 +193,7 @@ const StorageFilePage = ({ fileName, fileStats, onReload }: StorageFilePageProps
</>
)}
{config?.storage_browser.enable_file_download_button && (
<a href={`${DOWNLOAD_API_URL}${fileStats.path}`}>
<a href={fileDownloadUrl}>
<PrimaryButton
data-testid="preview--download--button"
data-event=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ let num_of_pending_uploads = 0;

function initUploader(path, _parent, el, labels) {
let uploader;
if (window.getLastKnownConfig().hue_config.enable_chunked_file_uploader) {
if (window.getLastKnownConfig().storage_browser.enable_chunked_file_upload) {
const action = '/filebrowser/upload/chunks/';
const qqTemplate = document.createElement('div');
qqTemplate.id = 'qq-template';
Expand Down
28 changes: 14 additions & 14 deletions desktop/core/src/desktop/js/reactComponents/FileChooser/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ export const FILESYSTEMS_API_URL = '/api/v1/storage/filesystems';
export const FILE_STATS_API_URL = '/api/v1/storage/stat';
export const LIST_DIRECTORY_API_URL = '/api/v1/storage/list';
export const FILE_PREVIEW_API_URL = '/api/v1/storage/display';
export const DOWNLOAD_API_URL = '/filebrowser/download=';
export const DOWNLOAD_API_URL = '/api/v1/storage/download';
export const CONTENT_SUMMARY_API_URL = '/api/v1/storage/content_summary';
export const SAVE_FILE_API_URL = '/api/v1/storage/save';
export const UPLOAD_FILE_URL = '/filebrowser/upload/file';
export const CHUNK_UPLOAD_URL = '/filebrowser/upload/chunks/file';
export const CHUNK_UPLOAD_COMPLETE_URL = '/filebrowser/upload/complete';
export const CREATE_FILE_API_URL = '/api/v1/storage/create/file/';
export const CREATE_DIRECTORY_API_URL = '/api/v1/storage/create/directory/';
export const RENAME_API_URL = '/api/v1/storage/rename/';
export const SET_REPLICATION_API_URL = '/api/v1/storage/replication/';
export const DELETION_API_URL = '/api/v1/storage/delete/';
export const UPLOAD_FILE_URL = '/api/v1/storage/upload/file';
export const CHUNK_UPLOAD_URL = '/api/v1/storage/upload/chunks';
export const CHUNK_UPLOAD_COMPLETE_URL = '/api/v1/storage/upload/complete';
export const CREATE_FILE_API_URL = '/api/v1/storage/create/file';
export const CREATE_DIRECTORY_API_URL = '/api/v1/storage/create/directory';
export const RENAME_API_URL = '/api/v1/storage/rename';
export const SET_REPLICATION_API_URL = '/api/v1/storage/replication';
export const DELETION_API_URL = '/api/v1/storage/delete';
export const BULK_DELETION_API_URL = '/api/v1/storage/delete/bulk';
export const COMPRESS_API_URL = '/api/v1/storage/compress';
export const EXTRACT_API_URL = '/api/v1/storage/extract_archive';
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 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
6 changes: 3 additions & 3 deletions desktop/core/src/desktop/static/desktop/js/listdir-inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ var FileBrowserModel = function (files, page, breadcrumbs, currentDirPath) {
});

self.isTaskServerEnabled = ko.computed(function() {
return window.getLastKnownConfig().hue_config.enable_chunked_file_uploader && window.getLastKnownConfig().hue_config.enable_task_server;
return window.getLastKnownConfig().storage_browser.enable_chunked_file_upload && window.getLastKnownConfig().hue_config.enable_task_server;
});

self.scheme = ko.pureComputed(function () {
Expand Down Expand Up @@ -1393,7 +1393,7 @@ var FileBrowserModel = function (files, page, breadcrumbs, currentDirPath) {
var uploader;
var scheduleUpload;

if ((window.getLastKnownConfig().hue_config.enable_chunked_file_uploader) && (window.getLastKnownConfig().hue_config.enable_task_server)) {
if ((window.getLastKnownConfig().storage_browser.enable_chunked_file_upload) && (window.getLastKnownConfig().hue_config.enable_task_server)) {

self.pendingUploads(0);
var action = "/filebrowser/upload/chunks/";
Expand Down Expand Up @@ -1517,7 +1517,7 @@ var FileBrowserModel = function (files, page, breadcrumbs, currentDirPath) {
});
}
// Chunked Fileuploader without Taskserver
else if ((window.getLastKnownConfig().hue_config.enable_chunked_file_uploader) && !(window.getLastKnownConfig().hue_config.enable_task_server)) {
else if ((window.getLastKnownConfig().storage_browser.enable_chunked_file_upload) && !(window.getLastKnownConfig().hue_config.enable_task_server)) {
self.pendingUploads(0);
var action = "/filebrowser/upload/chunks/";
uploader = new qq.FileUploader({
Expand Down

0 comments on commit bd8e80c

Please sign in to comment.