1
0
mirror of https://github.com/immich-app/immich.git synced 2025-08-09 23:17:29 +02:00

refactor(server): env validation (#13817)

This commit is contained in:
Jason Rasmussen
2024-10-30 05:00:41 -04:00
committed by GitHub
parent 19eb3ed8b9
commit 0f668fd5c6
8 changed files with 305 additions and 149 deletions

View File

@@ -25,6 +25,7 @@ import {
import { CronJob } from 'cron';
import { DateTime } from 'luxon';
import sanitize from 'sanitize-filename';
import { isIP, isIPRange } from 'validator';
@Injectable()
export class ParseMeUUIDPipe extends ParseUUIDPipe {
@@ -228,3 +229,32 @@ export function MaxDateString(
validationOptions,
);
}
type IsIPRangeOptions = { requireCIDR?: boolean };
export function IsIPRange(options: IsIPRangeOptions, validationOptions?: ValidationOptions): PropertyDecorator {
const { requireCIDR } = { requireCIDR: true, ...options };
return ValidateBy(
{
name: 'isIPRange',
validator: {
validate: (value): boolean => {
if (isIPRange(value)) {
return true;
}
if (!requireCIDR && isIP(value)) {
return true;
}
return false;
},
defaultMessage: buildMessage(
(eachPrefix) => eachPrefix + '$property must be an ip address, or ip address range',
validationOptions,
),
},
},
validationOptions,
);
}