mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 12:08:02 -05:00
Refactor config utils to use functions instead of consts
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
9fcc3c6cee
commit
235d7efa19
1 changed files with 7 additions and 12 deletions
|
@ -4,22 +4,17 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export const toArrayConfig: (
|
||||
configValue: string,
|
||||
separator?: string,
|
||||
) => string[] = (configValue: string, separator = ',') => {
|
||||
export function toArrayConfig(configValue: string, separator = ','): string[] {
|
||||
if (!configValue) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!configValue.includes(separator)) {
|
||||
return [configValue.trim()];
|
||||
}
|
||||
|
||||
return configValue.split(separator).map((arrayItem) => arrayItem.trim());
|
||||
};
|
||||
}
|
||||
|
||||
export const buildErrorMessage = (errorMessages: string[]): string => {
|
||||
export function buildErrorMessage(errorMessages: string[]): string {
|
||||
let totalErrorMessage = 'There were some errors with your configuration:';
|
||||
for (const message of errorMessages) {
|
||||
totalErrorMessage += '\n - ';
|
||||
|
@ -28,14 +23,14 @@ export const buildErrorMessage = (errorMessages: string[]): string => {
|
|||
totalErrorMessage +=
|
||||
'\nFor further information, have a look at our configuration docs at https://docs.hedgedoc.org/configuration';
|
||||
return totalErrorMessage;
|
||||
};
|
||||
}
|
||||
|
||||
export const replaceAuthErrorsWithEnvironmentVariables = (
|
||||
export function replaceAuthErrorsWithEnvironmentVariables(
|
||||
message: string,
|
||||
name: string,
|
||||
replacement: string,
|
||||
arrayOfNames: string[],
|
||||
): string => {
|
||||
): string {
|
||||
// this builds a regex like /"gitlab\[(\d+)]\./ to extract the position in the arrayOfNames
|
||||
const regex = new RegExp('"' + name + '\\[(\\d+)]\\.', 'g');
|
||||
message = message.replace(
|
||||
|
@ -91,4 +86,4 @@ export const replaceAuthErrorsWithEnvironmentVariables = (
|
|||
message = message.replace('.rolesClaim', '_ROLES_CLAIM');
|
||||
message = message.replace('.accessRole', '_ACCESS_ROLE');
|
||||
return message;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue