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