mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-03 04:28:45 -05:00
f4a580cf2a
This commit separates the app config object from a new note config object. This was done to separate different concerns in different config files. Especially if the number of settings that are about notes increase, it is a good idea to keep them separate from the app config. Signed-off-by: Philip Molares <philip.molares@udo.edu>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import { registerAs } from '@nestjs/config';
|
|
import * as Joi from 'joi';
|
|
|
|
import { buildErrorMessage, parseOptionalInt, toArrayConfig } from './utils';
|
|
|
|
export interface NoteConfig {
|
|
forbiddenNoteIds: string[];
|
|
maxDocumentLength: number;
|
|
}
|
|
|
|
const schema = Joi.object({
|
|
forbiddenNoteIds: Joi.array()
|
|
.items(Joi.string())
|
|
.optional()
|
|
.default([])
|
|
.label('HD_FORBIDDEN_NOTE_IDS'),
|
|
maxDocumentLength: Joi.number()
|
|
.default(100000)
|
|
.optional()
|
|
.label('HD_MAX_DOCUMENT_LENGTH'),
|
|
});
|
|
|
|
export default registerAs('noteConfig', () => {
|
|
const noteConfig = schema.validate(
|
|
{
|
|
forbiddenNoteIds: toArrayConfig(process.env.HD_FORBIDDEN_NOTE_IDS, ','),
|
|
maxDocumentLength: parseOptionalInt(process.env.HD_MAX_DOCUMENT_LENGTH),
|
|
},
|
|
{
|
|
abortEarly: false,
|
|
presence: 'required',
|
|
},
|
|
);
|
|
if (noteConfig.error) {
|
|
const errorMessages = noteConfig.error.details.map(
|
|
(detail) => detail.message,
|
|
);
|
|
throw new Error(buildErrorMessage(errorMessages));
|
|
}
|
|
return noteConfig.value as NoteConfig;
|
|
});
|