Skip to content

Commit 3ba14db

Browse files
committed
prettier
1 parent 2b9f2dc commit 3ba14db

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

src/Routers/PagesRouter.js

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,34 @@ import Page from '../Page';
1111
// All pages with custom page key for reference and file name
1212
const pages = Object.freeze({
1313
passwordReset: new Page({ id: 'passwordReset', defaultFile: 'password_reset.html' }),
14-
passwordResetSuccess: new Page({ id: 'passwordResetSuccess', defaultFile: 'password_reset_success.html' }),
15-
passwordResetLinkInvalid: new Page({ id: 'passwordResetLinkInvalid', defaultFile: 'password_reset_link_invalid.html' }),
16-
emailVerificationSuccess: new Page({ id: 'emailVerificationSuccess', defaultFile: 'email_verification_success.html' }),
17-
emailVerificationSendFail: new Page({ id: 'emailVerificationSendFail', defaultFile: 'email_verification_send_fail.html' }),
18-
emailVerificationSendSuccess: new Page({ id: 'emailVerificationSendSuccess', defaultFile: 'email_verification_send_success.html' }),
19-
emailVerificationLinkInvalid: new Page({ id: 'emailVerificationLinkInvalid', defaultFile: 'email_verification_link_invalid.html' }),
20-
emailVerificationLinkExpired: new Page({ id: 'emailVerificationLinkExpired', defaultFile: 'email_verification_link_expired.html' }),
14+
passwordResetSuccess: new Page({
15+
id: 'passwordResetSuccess',
16+
defaultFile: 'password_reset_success.html',
17+
}),
18+
passwordResetLinkInvalid: new Page({
19+
id: 'passwordResetLinkInvalid',
20+
defaultFile: 'password_reset_link_invalid.html',
21+
}),
22+
emailVerificationSuccess: new Page({
23+
id: 'emailVerificationSuccess',
24+
defaultFile: 'email_verification_success.html',
25+
}),
26+
emailVerificationSendFail: new Page({
27+
id: 'emailVerificationSendFail',
28+
defaultFile: 'email_verification_send_fail.html',
29+
}),
30+
emailVerificationSendSuccess: new Page({
31+
id: 'emailVerificationSendSuccess',
32+
defaultFile: 'email_verification_send_success.html',
33+
}),
34+
emailVerificationLinkInvalid: new Page({
35+
id: 'emailVerificationLinkInvalid',
36+
defaultFile: 'email_verification_link_invalid.html',
37+
}),
38+
emailVerificationLinkExpired: new Page({
39+
id: 'emailVerificationLinkExpired',
40+
defaultFile: 'email_verification_link_expired.html',
41+
}),
2142
});
2243

2344
// All page parameters for reference to be used as template placeholders or query params
@@ -36,8 +57,8 @@ const pageParamHeaderPrefix = 'x-parse-page-param-';
3657

3758
// The errors being thrown
3859
const errors = Object.freeze({
39-
jsonFailedFileLoading: "failed to load JSON file",
40-
fileOutsideAllowedScope: "not allowed to read file outside of pages directory"
60+
jsonFailedFileLoading: 'failed to load JSON file',
61+
fileOutsideAllowedScope: 'not allowed to read file outside of pages directory',
4162
});
4263

4364
export class PagesRouter extends PromiseRouter {
@@ -50,9 +71,7 @@ export class PagesRouter extends PromiseRouter {
5071

5172
// Set instance properties
5273
this.pagesConfig = pages;
53-
this.pagesEndpoint = pages.pagesEndpoint
54-
? pages.pagesEndpoint
55-
: 'apps';
74+
this.pagesEndpoint = pages.pagesEndpoint ? pages.pagesEndpoint : 'apps';
5675
this.pagesPath = pages.pagesPath
5776
? path.resolve('./', pages.pagesPath)
5877
: path.resolve(__dirname, '../../public');
@@ -121,7 +140,7 @@ export class PagesRouter extends PromiseRouter {
121140
[pageParams.appName]: config.appName,
122141
[pageParams.token]: req.query.token,
123142
[pageParams.username]: req.query.username,
124-
[pageParams.publicServerUrl]: config.publicServerURL
143+
[pageParams.publicServerUrl]: config.publicServerURL,
125144
};
126145
return this.goToPage(req, pages.passwordReset, params);
127146
}
@@ -289,7 +308,10 @@ export class PagesRouter extends PromiseRouter {
289308
if (config.pages.enableLocalization && locale) {
290309
return Utils.getLocalizedPath(defaultPath, locale).then(({ path, subdir }) =>
291310
redirect
292-
? this.redirectResponse(this.composePageUrl(defaultFile, config.publicServerURL, subdir), params)
311+
? this.redirectResponse(
312+
this.composePageUrl(defaultFile, config.publicServerURL, subdir),
313+
params
314+
)
293315
: this.pageResponse(path, params, placeholders)
294316
);
295317
} else {
@@ -356,7 +378,6 @@ export class PagesRouter extends PromiseRouter {
356378
* translation was found.
357379
*/
358380
getJsonTranslation(locale) {
359-
360381
// If there is no JSON resource
361382
if (this.jsonParameters === undefined) {
362383
return {};
@@ -366,11 +387,12 @@ export class PagesRouter extends PromiseRouter {
366387
locale = locale || this.pagesConfig.localizationFallbackLocale;
367388

368389
// Get matching translation by locale, language or fallback locale
369-
const language = locale.split("-")[0];
370-
const resource = this.jsonParameters[locale]
371-
|| this.jsonParameters[language]
372-
|| this.jsonParameters[this.pagesConfig.localizationFallbackLocale]
373-
|| {};
390+
const language = locale.split('-')[0];
391+
const resource =
392+
this.jsonParameters[locale] ||
393+
this.jsonParameters[language] ||
394+
this.jsonParameters[this.pagesConfig.localizationFallbackLocale] ||
395+
{};
374396
const translation = resource.translation || {};
375397
return translation;
376398
}
@@ -385,7 +407,6 @@ export class PagesRouter extends PromiseRouter {
385407
* translation was found.
386408
*/
387409
getJsonPlaceholders(locale, params = {}) {
388-
389410
// If localization is disabled or there is no JSON resource
390411
if (!this.pagesConfig.enableLocalization || !this.pagesConfig.localizationJsonPath) {
391412
return {};
@@ -422,11 +443,12 @@ export class PagesRouter extends PromiseRouter {
422443
}
423444

424445
// Get config placeholders; can be an object, a function or an async function
425-
let configPlaceholders = typeof this.pagesConfig.placeholders === 'function'
426-
? this.pagesConfig.placeholders()
427-
: Object.prototype.toString.call(this.pagesConfig.placeholders) === '[object Object]'
428-
? this.pagesConfig.placeholders
429-
: {};
446+
let configPlaceholders =
447+
typeof this.pagesConfig.placeholders === 'function'
448+
? this.pagesConfig.placeholders()
449+
: Object.prototype.toString.call(this.pagesConfig.placeholders) === '[object Object]'
450+
? this.pagesConfig.placeholders
451+
: {};
430452
if (configPlaceholders instanceof Promise) {
431453
configPlaceholders = await configPlaceholders;
432454
}
@@ -477,7 +499,6 @@ export class PagesRouter extends PromiseRouter {
477499
* @returns {Promise<String>} The file content.
478500
*/
479501
async readFile(filePath) {
480-
481502
// Normalize path to prevent it from containing any directory changing
482503
// UNIX patterns which could expose the whole file system, e.g.
483504
// `http://example.com/parse/apps/../file.txt` requests a file outside
@@ -486,7 +507,7 @@ export class PagesRouter extends PromiseRouter {
486507

487508
// Abort if the path is outside of the path directory scope
488509
if (!normalizedPath.startsWith(this.pagesPath)) {
489-
throw(errors.fileOutsideAllowedScope);
510+
throw errors.fileOutsideAllowedScope;
490511
}
491512

492513
return await fs.readFile(normalizedPath, 'utf-8');
@@ -503,7 +524,7 @@ export class PagesRouter extends PromiseRouter {
503524
const json = require(path.resolve('./', this.pagesConfig.localizationJsonPath));
504525
this.jsonParameters = json;
505526
} catch (e) {
506-
throw(errors.jsonFailedFileLoading);
527+
throw errors.jsonFailedFileLoading;
507528
}
508529
}
509530

@@ -531,10 +552,10 @@ export class PagesRouter extends PromiseRouter {
531552
*/
532553
getLocale(req) {
533554
const locale =
534-
(req.query || {})[pageParams.locale]
535-
|| (req.body || {})[pageParams.locale]
536-
|| (req.params || {})[pageParams.locale]
537-
|| (req.headers || {})[pageParamHeaderPrefix + pageParams.locale];
555+
(req.query || {})[pageParams.locale] ||
556+
(req.body || {})[pageParams.locale] ||
557+
(req.params || {})[pageParams.locale] ||
558+
(req.headers || {})[pageParamHeaderPrefix + pageParams.locale];
538559
return locale;
539560
}
540561

0 commit comments

Comments
 (0)