@@ -151,6 +151,33 @@ export class PublicAPIRouter extends PromiseRouter {
151
151
} ) ;
152
152
}
153
153
154
+ var invalid_verification_link_page_template_file = null ;
155
+ /**
156
+ * loading the template for invalid verification link page
157
+ * this method returns the template for the page stored in memory
158
+ * on first access it will load the template file from disk
159
+ */
160
+ loadInvalidVerificationLinkPageTemplate ( ) {
161
+ if ( invalid_verification_link_page_template_file ) {
162
+ return invalid_verification_link_page_template_file ;
163
+ } else {
164
+ invalid_verification_link_page_template_file = loadPageTemplateFile ( "invalid_verification_link" ) ;
165
+ if ( invalid_verification_link_page_template_file ) {
166
+ invalid_verification_link_page_template_file = invalid_verification_link_page_template_file . replace ( "PARSE_SERVER_URL" , `'${ config . publicServerURL } '` ) ;
167
+ }
168
+ return invalid_verification_link_page_template_file ;
169
+ }
170
+ }
171
+
172
+ loadPageTemplateFile ( filename ) {
173
+ fs . readFile ( path . resolve ( views , filename ) , 'utf-8' , ( err , data ) => {
174
+ if ( err ) {
175
+ return null ;
176
+ }
177
+ return data ;
178
+ } ) ;
179
+ }
180
+
154
181
invalidVerificationLink ( req ) {
155
182
const config = req . config ;
156
183
if ( ! config . publicServerURL ) {
@@ -161,18 +188,19 @@ export class PublicAPIRouter extends PromiseRouter {
161
188
}
162
189
163
190
if ( req . query . username && req . params . appId ) {
164
- // Should we keep the file in memory or leave like that?
165
- fs . readFile ( path . resolve ( views , "invalid_verification_link" ) , 'utf-8' , ( err , data ) => {
166
- if ( err ) {
167
- return Promise . reject ( err ) ;
168
- }
169
- data = data . replace ( "PARSE_SERVER_URL" , `'${ config . publicServerURL } '` ) ;
170
- data = data . replace ( "USERNAME" , `'${ req . query . username } '` ) ;
171
- data = data . replace ( "APPID" , `'${ req . params . appId } '` ) ;
191
+ // load page template from file or from memory
192
+ var invalid_verification_link_page = loadInvalidVerificationLinkPageTemplate ( ) ;
193
+ if ( invalid_verification_link_page ) {
194
+ // replace dynamic template attributes
195
+ invalid_verification_link_page = invalid_verification_link_page . replace ( "USERNAME" , `'${ req . query . username } '` ) ;
196
+ invalid_verification_link_page = invalid_verification_link_page . replace ( "APPID" , `'${ req . params . appId } '` ) ;
197
+ // send page to the client
172
198
return Promise . resolve ( {
173
- text : data
174
- } )
175
- } ) ;
199
+ text : invalid_verification_link_page
200
+ } ) ;
201
+ } else {
202
+ Promise . reject ( "Could not load invalid_verification_link template." ) ;
203
+ }
176
204
} else {
177
205
return this . invalidLink ( req ) ;
178
206
}
0 commit comments