mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { Type } from 'class-transformer';
|
|
import {
|
|
IsNotEmpty,
|
|
IsObject,
|
|
IsString,
|
|
Validate,
|
|
ValidateIf,
|
|
ValidateNested,
|
|
ValidatorConstraint,
|
|
ValidatorConstraintInterface,
|
|
} from 'class-validator';
|
|
import { ValidateBoolean, validateCronExpression } from 'src/validation';
|
|
|
|
const isEnabled = (config: SystemConfigLibraryScanDto) => config.enabled;
|
|
|
|
@ValidatorConstraint({ name: 'cronValidator' })
|
|
class CronValidator implements ValidatorConstraintInterface {
|
|
validate(expression: string): boolean {
|
|
return validateCronExpression(expression);
|
|
}
|
|
}
|
|
|
|
export class SystemConfigLibraryScanDto {
|
|
@ValidateBoolean()
|
|
enabled!: boolean;
|
|
|
|
@ValidateIf(isEnabled)
|
|
@IsNotEmpty()
|
|
@Validate(CronValidator, { message: 'Invalid cron expression' })
|
|
@IsString()
|
|
cronExpression!: string;
|
|
}
|
|
|
|
export class SystemConfigLibraryWatchDto {
|
|
@ValidateBoolean()
|
|
enabled!: boolean;
|
|
}
|
|
|
|
export class SystemConfigLibraryDto {
|
|
@Type(() => SystemConfigLibraryScanDto)
|
|
@ValidateNested()
|
|
@IsObject()
|
|
scan!: SystemConfigLibraryScanDto;
|
|
|
|
@Type(() => SystemConfigLibraryWatchDto)
|
|
@ValidateNested()
|
|
@IsObject()
|
|
watch!: SystemConfigLibraryWatchDto;
|
|
}
|