@@ -5,7 +5,7 @@ import {httpDownload, httpUpload, initHttpGateway} from '../http-gateway';
55import { handleHttpGatewayDrop , httpGatewayReadAsArrayBuffer , httpGatewayReadChunkAsArrayBuffer , httpGatewaySelectFileFolderDialog , httpGetAllTransfers , httpGetTransfer , httpRemoveTransfer , httpStopTransfer , sendTransferUpdate } from '../http-gateway/core' ;
66import { asperaSdk } from '../index' ;
77import { AsperaSdkInfo , AsperaSdkClientInfo , TransferResponse } from '../models/aspera-sdk.model' ;
8- import { CustomBrandingOptions , DataTransferResponse , DropzoneEventData , DropzoneEventType , DropzoneOptions , AsperaSdkSpec , BrowserStyleFile , AsperaSdkTransfer , FileDialogOptions , FolderDialogOptions , InitOptions , ModifyTransferOptions , Pagination , PaginatedFilesResponse , ResumeTransferOptions , TransferSpec , WebsocketEvent , ReadChunkAsArrayBufferResponse , ReadAsArrayBufferResponse , OpenRpcSpec , SdkCapabilities , GetChecksumOptions , ChecksumFileResponse , ReadDirectoryOptions , ReadDirectoryResponse , ShowPreferencesPageOptions , PreferencesPage , TestSshPortsOptions } from '../models/models' ;
8+ import { CustomBrandingOptions , DataTransferResponse , DropzoneEventData , DropzoneEventType , DropzoneOptions , AsperaSdkSpec , BrowserStyleFile , AsperaSdkTransfer , FileDialogOptions , FolderDialogOptions , SaveFileDialogOptions , InitOptions , ModifyTransferOptions , Pagination , PaginatedFilesResponse , ResumeTransferOptions , TransferSpec , WebsocketEvent , ReadChunkAsArrayBufferResponse , ReadAsArrayBufferResponse , OpenRpcSpec , SdkCapabilities , GetChecksumOptions , ChecksumFileResponse , ReadDirectoryOptions , ReadDirectoryResponse , ShowPreferencesPageOptions , PreferencesPage , TestSshPortsOptions } from '../models/models' ;
99import { Connect , ConnectInstaller } from '@ibm-aspera/connect-sdk-js' ;
1010import { initConnect } from '../connect/core' ;
1111import * as ConnectTypes from '@ibm-aspera/connect-sdk-js/dist/esm/core/types' ;
@@ -544,6 +544,50 @@ export const showSelectFolderDialog = (options?: FolderDialogOptions): Promise<D
544544 return promiseInfo . promise ;
545545} ;
546546
547+ /**
548+ * Displays a save file dialog for the user to choose a save location and filename.
549+ *
550+ * Supported for Connect and IBM Aspera for desktop. Not supported for HTTP Gateway.
551+ *
552+ * @param options save file dialog options
553+ *
554+ * @returns a promise that resolves with the selected save path and rejects if user cancels dialog
555+ */
556+ export const showSaveFileDialog = ( options ?: SaveFileDialogOptions ) : Promise < DataTransferResponse > => {
557+ if ( asperaSdk . useHttpGateway ) {
558+ return throwError ( messages . showSaveFileDialogNotSupported ) ;
559+ }
560+
561+ if ( asperaSdk . useConnect ) {
562+ const connectPromiseInfo = generatePromiseObjects ( ) ;
563+ asperaSdk . globals . connect . showSaveFileDialog ( {
564+ success : ( data : any ) => connectPromiseInfo . resolver ( data as unknown as DataTransferResponse ) ,
565+ error : ( error : any ) => connectPromiseInfo . rejecter ( error ) ,
566+ } , options ) ;
567+ return connectPromiseInfo . promise ;
568+ }
569+
570+ if ( ! asperaSdk . isReady ) {
571+ return throwError ( messages . serverNotVerified ) ;
572+ }
573+
574+ const promiseInfo = generatePromiseObjects ( ) ;
575+
576+ const payload = {
577+ options : options || { } ,
578+ app_id : asperaSdk . globals . appId ,
579+ } ;
580+
581+ client . request ( 'show_save_file_dialog' , payload )
582+ . then ( ( data : any ) => promiseInfo . resolver ( data ) )
583+ . catch ( error => {
584+ errorLog ( messages . showSaveFileDialogFailed , error ) ;
585+ promiseInfo . rejecter ( generateErrorBody ( messages . showSaveFileDialogFailed , error ) ) ;
586+ } ) ;
587+
588+ return promiseInfo . promise ;
589+ } ;
590+
547591/**
548592 * Shows the about page of the transfer client.
549593 *
@@ -1295,7 +1339,7 @@ const supportsMethod = (method: string): boolean => {
12951339 // We currently do not support calculating file checksums when using HTTP Gateway. In theory it should be possible
12961340 // to calculate this directly in the browser similar to how `readAsArrayBuffer()` is implemented.
12971341 // HTTP Gateway also does not support showing native transfer client UI (about, preferences, etc.).
1298- if ( asperaSdk . useHttpGateway && ( method === 'get_checksum' || method === 'show_about' || method === 'open_preferences' || method === 'show_transfer_manager' || method === 'show_transfer_monitor' || method === 'authenticate' || method === 'test_ssh_ports' || method === 'read_directory' ) ) {
1342+ if ( asperaSdk . useHttpGateway && ( method === 'get_checksum' || method === 'show_about' || method === 'open_preferences' || method === 'show_transfer_manager' || method === 'show_transfer_monitor' || method === 'authenticate' || method === 'test_ssh_ports' || method === 'show_save_file_dialog' || method === ' read_directory') ) {
12991343 return false ;
13001344 }
13011345
@@ -1342,6 +1386,7 @@ export const getCapabilities = (): SdkCapabilities => {
13421386 showTransferMonitor : supportsMethod ( 'show_transfer_monitor' ) ,
13431387 authenticate : supportsMethod ( 'authenticate' ) ,
13441388 testSshPorts : supportsMethod ( 'test_ssh_ports' ) ,
1389+ showSaveFileDialog : supportsMethod ( 'show_save_file_dialog' ) ,
13451390 readDirectory : supportsMethod ( 'read_directory' ) ,
13461391 } ;
13471392} ;
0 commit comments