@@ -29,29 +29,29 @@ interface RDeployChallenge {
29
29
}
30
30
31
31
class 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 [ ] = [ ]
36
36
37
37
private ready = false
38
38
private downloadMap : Map < string , string >
39
39
40
- constructor ( options : RDeployBlobProviderOptions ) {
40
+ constructor ( _options : RDeployBlobProviderOptions ) {
41
41
super ( )
42
- options = {
42
+ const options : Required < RDeployBlobProviderOptions > = {
43
43
updateInterval : 60 * 1000 ,
44
- ...options
44
+ ..._options
45
45
}
46
46
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 )
50
50
51
- this . downloadMap = new Map ( )
51
+ this . downloadMap = new Map < string , string > ( )
52
52
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 )
55
55
. then ( async files => {
56
56
await Promise . all ( files . map ( async file => {
57
57
const filePath = path . join ( fileDir , file )
@@ -68,25 +68,29 @@ class RDeployBlobProvider extends EventEmitter implements Provider {
68
68
69
69
// When done uploading files, allow updates
70
70
this . ready = true
71
- this . _update ( )
71
+ this . update ( )
72
72
} )
73
73
}
74
74
75
- _update ( ) : void {
75
+ private update ( ) : void {
76
76
// Prevent updates if downloads not initialized
77
77
if ( ! this . ready ) return
78
78
79
- fs . readFile ( path . join ( this . _rDeployDirectory , 'config.json' ) , 'utf8' )
79
+ fs . readFile ( path . join ( this . rDeployDirectory , 'config.json' ) , 'utf8' )
80
80
. then ( ( data : string ) => {
81
81
try {
82
- const rawChallenges : RDeployChallenge [ ] = JSON . parse ( data )
82
+ const rawChallenges = JSON . parse ( data ) as RDeployChallenge [ ]
83
83
84
84
this . challenges = rawChallenges . map ( ( chall : RDeployChallenge ) : Challenge => {
85
85
const downloadUrls : File [ ] = chall . files . map ( file => {
86
86
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
+ }
87
91
return {
88
92
name : normalize . normalizeDownload ( basename ) ,
89
- url : this . downloadMap . get ( basename )
93
+ url : fileUrl
90
94
}
91
95
} )
92
96
@@ -109,7 +113,7 @@ class RDeployBlobProvider extends EventEmitter implements Provider {
109
113
}
110
114
111
115
forceUpdate ( ) : void {
112
- this . _update ( )
116
+ this . update ( )
113
117
}
114
118
115
119
updateChallenge ( chall : Challenge ) : void {
@@ -135,7 +139,7 @@ class RDeployBlobProvider extends EventEmitter implements Provider {
135
139
}
136
140
137
141
cleanup ( ) : void {
138
- clearInterval ( this . _interval )
142
+ clearInterval ( this . interval )
139
143
}
140
144
}
141
145
0 commit comments