@@ -27,64 +27,52 @@ const provider: common.ConfigFileAuthenticationDetailsProvider = new common.Conf
27
27
*/
28
28
29
29
const args = process . argv . slice ( 2 ) ;
30
- if ( args . length !== 2 ) {
30
+ if ( args . length !== 3 ) {
31
31
console . error (
32
32
"Unexpected number of arguments received. Please pass absloute directory path to read files from"
33
33
) ;
34
34
process . exit ( - 1 ) ;
35
35
}
36
36
37
- const directoryPath : string = args [ 0 ] ; // for eg : "/Users/Abc/upload-manager";
37
+ const filePath : string = args [ 0 ] ; // for eg : "/Users/Abc/upload-manager";
38
38
const bucketName = args [ 1 ] ;
39
+ const namespaceName = args [ 2 ]
39
40
const serviceName = "objectstorage"
40
41
41
42
const client = new ObjectStorageClient ( { authenticationDetailsProvider : provider } ) ;
42
43
client . region = Region . US_PHOENIX_1 ;
43
44
44
45
( 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 } ` ) ;
50
49
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 ) ;
54
54
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 ) ;
59
73
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
+ }
90
78
} ) ( ) ;
0 commit comments