You've already forked immich
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:
@@ -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,
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user