mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
refactor(server): env validation (#13817)
This commit is contained in:
parent
19eb3ed8b9
commit
0f668fd5c6
8 changed files with 305 additions and 149 deletions
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue