2022-01-30 09:48:59 -05:00
|
|
|
/*
|
|
|
|
* 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';
|
|
|
|
|
2022-03-04 17:43:09 -05:00
|
|
|
import { buildErrorMessage, parseOptionalNumber, toArrayConfig } from './utils';
|
2022-01-30 09:48:59 -05:00
|
|
|
|
|
|
|
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, ','),
|
2022-03-04 17:43:09 -05:00
|
|
|
maxDocumentLength: parseOptionalNumber(
|
|
|
|
process.env.HD_MAX_DOCUMENT_LENGTH,
|
|
|
|
),
|
2022-01-30 09:48:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
});
|