@@ -29,29 +29,29 @@ interface RDeployChallenge {
2929}
3030
3131class RDeployBlobProvider extends EventEmitter implements Provider {
32- private _updateInterval : number
33- private _rDeployDirectory : string
34- private _interval : NodeJS . Timeout
35- private challenges : Challenge [ ]
32+ private updateInterval : number
33+ private rDeployDirectory : string
34+ private interval : NodeJS . Timeout
35+ private challenges : Challenge [ ] = [ ]
3636
3737 private ready = false
3838 private downloadMap : Map < string , string >
3939
40- constructor ( options : RDeployBlobProviderOptions ) {
40+ constructor ( _options : RDeployBlobProviderOptions ) {
4141 super ( )
42- options = {
42+ const options : Required < RDeployBlobProviderOptions > = {
4343 updateInterval : 60 * 1000 ,
44- ...options
44+ ..._options
4545 }
4646
47- this . _updateInterval = options . updateInterval
48- this . _rDeployDirectory = path . join ( __dirname , '../../../../../' , options . rDeployDirectory )
49- this . _interval = setInterval ( ( ) => this . _update ( ) , this . _updateInterval )
47+ this . updateInterval = options . updateInterval
48+ this . rDeployDirectory = path . join ( __dirname , '../../../../../' , options . rDeployDirectory )
49+ this . interval = setInterval ( ( ) => this . update ( ) , this . updateInterval )
5050
51- this . downloadMap = new Map ( )
51+ this . downloadMap = new Map < string , string > ( )
5252
53- const fileDir = path . join ( this . _rDeployDirectory , options . rDeployFiles )
54- fs . readdir ( fileDir )
53+ const fileDir = path . join ( this . rDeployDirectory , options . rDeployFiles )
54+ void fs . readdir ( fileDir )
5555 . then ( async files => {
5656 await Promise . all ( files . map ( async file => {
5757 const filePath = path . join ( fileDir , file )
@@ -68,25 +68,29 @@ class RDeployBlobProvider extends EventEmitter implements Provider {
6868
6969 // When done uploading files, allow updates
7070 this . ready = true
71- this . _update ( )
71+ this . update ( )
7272 } )
7373 }
7474
75- _update ( ) : void {
75+ private update ( ) : void {
7676 // Prevent updates if downloads not initialized
7777 if ( ! this . ready ) return
7878
79- fs . readFile ( path . join ( this . _rDeployDirectory , 'config.json' ) , 'utf8' )
79+ fs . readFile ( path . join ( this . rDeployDirectory , 'config.json' ) , 'utf8' )
8080 . then ( ( data : string ) => {
8181 try {
82- const rawChallenges : RDeployChallenge [ ] = JSON . parse ( data )
82+ const rawChallenges = JSON . parse ( data ) as RDeployChallenge [ ]
8383
8484 this . challenges = rawChallenges . map ( ( chall : RDeployChallenge ) : Challenge => {
8585 const downloadUrls : File [ ] = chall . files . map ( file => {
8686 const basename = path . basename ( file )
87+ const fileUrl = this . downloadMap . get ( basename )
88+ if ( fileUrl === undefined ) {
89+ throw new Error ( `File not found: ${ basename } ` )
90+ }
8791 return {
8892 name : normalize . normalizeDownload ( basename ) ,
89- url : this . downloadMap . get ( basename )
93+ url : fileUrl
9094 }
9195 } )
9296
@@ -109,7 +113,7 @@ class RDeployBlobProvider extends EventEmitter implements Provider {
109113 }
110114
111115 forceUpdate ( ) : void {
112- this . _update ( )
116+ this . update ( )
113117 }
114118
115119 updateChallenge ( chall : Challenge ) : void {
@@ -135,7 +139,7 @@ class RDeployBlobProvider extends EventEmitter implements Provider {
135139 }
136140
137141 cleanup ( ) : void {
138- clearInterval ( this . _interval )
142+ clearInterval ( this . interval )
139143 }
140144}
141145
0 commit comments