@@ -27,64 +27,52 @@ const provider: common.ConfigFileAuthenticationDetailsProvider = new common.Conf
2727 */
2828
2929const args = process . argv . slice ( 2 ) ;
30- if ( args . length !== 2 ) {
30+ if ( args . length !== 3 ) {
3131 console . error (
3232 "Unexpected number of arguments received. Please pass absloute directory path to read files from"
3333 ) ;
3434 process . exit ( - 1 ) ;
3535}
3636
37- const directoryPath : string = args [ 0 ] ; // for eg : "/Users/Abc/upload-manager";
37+ const filePath : string = args [ 0 ] ; // for eg : "/Users/Abc/upload-manager";
3838const bucketName = args [ 1 ] ;
39+ const namespaceName = args [ 2 ]
3940const serviceName = "objectstorage"
4041
4142const client = new ObjectStorageClient ( { authenticationDetailsProvider : provider } ) ;
4243client . region = Region . US_PHOENIX_1 ;
4344
4445( async ( ) => {
45- // getting the namespsace
46- console . log ( "Getting the namespace..." ) ;
47- const request : requests . GetNamespaceRequest = { } ;
48- const response = await client . getNamespace ( request ) ;
49- const namespaceName = response . value ;
46+ try {
47+ // creating pre authentication request which generates the download url for the file
48+ console . time ( `Download Time ${ filePath } ` ) ;
5049
51- // Read files from the directory
52- readdir ( directoryPath , ( err , files ) => {
53- if ( err ) return console . log ( "Unable to scan directory: " + err ) ;
50+ // set expiry date for the download url.
51+ const today = new Date ( ) ;
52+ const neverExpires = new Date ( today ) ;
53+ neverExpires . setDate ( neverExpires . getDate ( ) + 25 ) ;
5454
55- files . forEach ( async filename => {
56- try {
57- // creating pre authentication request which generates the download url for the file
58- console . time ( `Download Time ${ filename } ` ) ;
55+ // use date for generating a random unique id which can be used as a par id
56+ const parUniqueId = Date . now ( ) ;
57+ const createPreauthenticatedRequestDetails = {
58+ name : parUniqueId . toString ( ) ,
59+ objectName : filePath ,
60+ accessType : models . CreatePreauthenticatedRequestDetails . AccessType . ObjectRead ,
61+ timeExpires : neverExpires
62+ } as models . CreatePreauthenticatedRequestDetails ;
63+ const createPreauthenticatedRequest : requests . CreatePreauthenticatedRequestRequest = {
64+ bucketName : bucketName ,
65+ namespaceName : namespaceName ,
66+ createPreauthenticatedRequestDetails : createPreauthenticatedRequestDetails
67+ } ;
68+ // create pre authenticated request to generate the url
69+ const resp = await client . createPreauthenticatedRequest ( createPreauthenticatedRequest ) ;
70+ const baseUrl = `https://${ serviceName } .${ common . Region . US_PHOENIX_1 . regionId } .${ common . Realm . OC1 . secondLevelDomain } `
71+ const downloadUrl = resp . preauthenticatedRequest . accessUri ;
72+ console . log ( "download url for the file " + filePath + " is " + baseUrl + downloadUrl ) ;
5973
60- // set expiry date for the download url.
61- const today = new Date ( ) ;
62- const neverExpires = new Date ( today ) ;
63- neverExpires . setDate ( neverExpires . getDate ( ) + 25 ) ;
64-
65- // use date for generating a random unique id which can be used as a par id
66- const parUniqueId = Date . now ( ) ;
67- const createPreauthenticatedRequestDetails = {
68- name : parUniqueId . toString ( ) ,
69- objectName : filename ,
70- accessType : models . CreatePreauthenticatedRequestDetails . AccessType . ObjectRead ,
71- timeExpires : neverExpires
72- } as models . CreatePreauthenticatedRequestDetails ;
73- const createPreauthenticatedRequest : requests . CreatePreauthenticatedRequestRequest = {
74- bucketName : bucketName ,
75- namespaceName : namespaceName ,
76- createPreauthenticatedRequestDetails : createPreauthenticatedRequestDetails
77- } ;
78- // create pre authenticated request to generate the url
79- const resp = await client . createPreauthenticatedRequest ( createPreauthenticatedRequest ) ;
80- const baseUrl = `https://${ serviceName } .${ common . Region . US_PHOENIX_1 . regionId } .${ common . Realm . OC1 . secondLevelDomain } `
81- const downloadUrl = resp . preauthenticatedRequest . accessUri ;
82- console . log ( "download url for the file " + filename + " is " + baseUrl + downloadUrl ) ;
83-
84- console . timeEnd ( `Download Time ${ filename } ` ) ;
85- } catch ( ex ) {
86- console . error ( `Failed due to ${ ex } ` ) ;
87- }
88- } ) ;
89- } ) ;
74+ console . timeEnd ( `Download Time ${ filePath } ` ) ;
75+ } catch ( ex ) {
76+ console . error ( `Failed due to ${ ex } ` ) ;
77+ }
9078} ) ( ) ;
0 commit comments