mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
refactor: validate enum (#19943)
This commit is contained in:
parent
68f249bc03
commit
351701c4d6
23 changed files with 161 additions and 225 deletions
|
|
@ -2,8 +2,6 @@ import { ApiProperty } from '@nestjs/swagger';
|
|||
import { Exclude, Transform, Type } from 'class-transformer';
|
||||
import {
|
||||
ArrayMinSize,
|
||||
IsBoolean,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
|
|
@ -34,7 +32,7 @@ import {
|
|||
VideoContainer,
|
||||
} from 'src/enum';
|
||||
import { ConcurrentQueueName } from 'src/types';
|
||||
import { IsCronExpression, IsDateStringFormat, Optional, ValidateBoolean } from 'src/validation';
|
||||
import { IsCronExpression, IsDateStringFormat, Optional, ValidateBoolean, ValidateEnum } from 'src/validation';
|
||||
|
||||
const isLibraryScanEnabled = (config: SystemConfigLibraryScanDto) => config.enabled;
|
||||
const isOAuthEnabled = (config: SystemConfigOAuthDto) => config.enabled;
|
||||
|
|
@ -82,24 +80,19 @@ export class SystemConfigFFmpegDto {
|
|||
@IsString()
|
||||
preset!: string;
|
||||
|
||||
@IsEnum(VideoCodec)
|
||||
@ApiProperty({ enumName: 'VideoCodec', enum: VideoCodec })
|
||||
@ValidateEnum({ enum: VideoCodec, name: 'VideoCodec' })
|
||||
targetVideoCodec!: VideoCodec;
|
||||
|
||||
@IsEnum(VideoCodec, { each: true })
|
||||
@ApiProperty({ enumName: 'VideoCodec', enum: VideoCodec, isArray: true })
|
||||
@ValidateEnum({ enum: VideoCodec, name: 'VideoCodec', each: true })
|
||||
acceptedVideoCodecs!: VideoCodec[];
|
||||
|
||||
@IsEnum(AudioCodec)
|
||||
@ApiProperty({ enumName: 'AudioCodec', enum: AudioCodec })
|
||||
@ValidateEnum({ enum: AudioCodec, name: 'AudioCodec' })
|
||||
targetAudioCodec!: AudioCodec;
|
||||
|
||||
@IsEnum(AudioCodec, { each: true })
|
||||
@ApiProperty({ enumName: 'AudioCodec', enum: AudioCodec, isArray: true })
|
||||
@ValidateEnum({ enum: AudioCodec, name: 'AudioCodec', each: true })
|
||||
acceptedAudioCodecs!: AudioCodec[];
|
||||
|
||||
@IsEnum(VideoContainer, { each: true })
|
||||
@ApiProperty({ enumName: 'VideoContainer', enum: VideoContainer, isArray: true })
|
||||
@ValidateEnum({ enum: VideoContainer, name: 'VideoContainer', each: true })
|
||||
acceptedContainers!: VideoContainer[];
|
||||
|
||||
@IsString()
|
||||
|
|
@ -131,8 +124,7 @@ export class SystemConfigFFmpegDto {
|
|||
@ValidateBoolean()
|
||||
temporalAQ!: boolean;
|
||||
|
||||
@IsEnum(CQMode)
|
||||
@ApiProperty({ enumName: 'CQMode', enum: CQMode })
|
||||
@ValidateEnum({ enum: CQMode, name: 'CQMode' })
|
||||
cqMode!: CQMode;
|
||||
|
||||
@ValidateBoolean()
|
||||
|
|
@ -141,19 +133,16 @@ export class SystemConfigFFmpegDto {
|
|||
@IsString()
|
||||
preferredHwDevice!: string;
|
||||
|
||||
@IsEnum(TranscodePolicy)
|
||||
@ApiProperty({ enumName: 'TranscodePolicy', enum: TranscodePolicy })
|
||||
@ValidateEnum({ enum: TranscodePolicy, name: 'TranscodePolicy' })
|
||||
transcode!: TranscodePolicy;
|
||||
|
||||
@IsEnum(TranscodeHWAccel)
|
||||
@ApiProperty({ enumName: 'TranscodeHWAccel', enum: TranscodeHWAccel })
|
||||
@ValidateEnum({ enum: TranscodeHWAccel, name: 'TranscodeHWAccel' })
|
||||
accel!: TranscodeHWAccel;
|
||||
|
||||
@ValidateBoolean()
|
||||
accelDecode!: boolean;
|
||||
|
||||
@IsEnum(ToneMapping)
|
||||
@ApiProperty({ enumName: 'ToneMapping', enum: ToneMapping })
|
||||
@ValidateEnum({ enum: ToneMapping, name: 'ToneMapping' })
|
||||
tonemap!: ToneMapping;
|
||||
}
|
||||
|
||||
|
|
@ -264,8 +253,7 @@ class SystemConfigLoggingDto {
|
|||
@ValidateBoolean()
|
||||
enabled!: boolean;
|
||||
|
||||
@ApiProperty({ enum: LogLevel, enumName: 'LogLevel' })
|
||||
@IsEnum(LogLevel)
|
||||
@ValidateEnum({ enum: LogLevel, name: 'LogLevel' })
|
||||
level!: LogLevel;
|
||||
}
|
||||
|
||||
|
|
@ -306,8 +294,7 @@ enum MapTheme {
|
|||
}
|
||||
|
||||
export class MapThemeDto {
|
||||
@IsEnum(MapTheme)
|
||||
@ApiProperty({ enum: MapTheme, enumName: 'MapTheme' })
|
||||
@ValidateEnum({ enum: MapTheme, name: 'MapTheme' })
|
||||
theme!: MapTheme;
|
||||
}
|
||||
|
||||
|
|
@ -368,8 +355,7 @@ class SystemConfigOAuthDto {
|
|||
@IsString()
|
||||
clientSecret!: string;
|
||||
|
||||
@IsEnum(OAuthTokenEndpointAuthMethod)
|
||||
@ApiProperty({ enum: OAuthTokenEndpointAuthMethod, enumName: 'OAuthTokenEndpointAuthMethod' })
|
||||
@ValidateEnum({ enum: OAuthTokenEndpointAuthMethod, name: 'OAuthTokenEndpointAuthMethod' })
|
||||
tokenEndpointAuthMethod!: OAuthTokenEndpointAuthMethod;
|
||||
|
||||
@IsInt()
|
||||
|
|
@ -431,7 +417,7 @@ class SystemConfigReverseGeocodingDto {
|
|||
}
|
||||
|
||||
class SystemConfigFacesDto {
|
||||
@IsBoolean()
|
||||
@ValidateBoolean()
|
||||
import!: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -450,12 +436,12 @@ class SystemConfigServerDto {
|
|||
@IsString()
|
||||
loginPageMessage!: string;
|
||||
|
||||
@IsBoolean()
|
||||
@ValidateBoolean()
|
||||
publicUsers!: boolean;
|
||||
}
|
||||
|
||||
class SystemConfigSmtpTransportDto {
|
||||
@IsBoolean()
|
||||
@ValidateBoolean()
|
||||
ignoreCert!: boolean;
|
||||
|
||||
@IsNotEmpty()
|
||||
|
|
@ -475,7 +461,7 @@ class SystemConfigSmtpTransportDto {
|
|||
}
|
||||
|
||||
export class SystemConfigSmtpDto {
|
||||
@IsBoolean()
|
||||
@ValidateBoolean()
|
||||
enabled!: boolean;
|
||||
|
||||
@ValidateIf(isEmailNotificationEnabled)
|
||||
|
|
@ -548,8 +534,7 @@ export class SystemConfigThemeDto {
|
|||
}
|
||||
|
||||
class SystemConfigGeneratedImageDto {
|
||||
@IsEnum(ImageFormat)
|
||||
@ApiProperty({ enumName: 'ImageFormat', enum: ImageFormat })
|
||||
@ValidateEnum({ enum: ImageFormat, name: 'ImageFormat' })
|
||||
format!: ImageFormat;
|
||||
|
||||
@IsInt()
|
||||
|
|
@ -567,13 +552,10 @@ class SystemConfigGeneratedImageDto {
|
|||
}
|
||||
|
||||
class SystemConfigGeneratedFullsizeImageDto {
|
||||
@IsBoolean()
|
||||
@Type(() => Boolean)
|
||||
@ApiProperty({ type: 'boolean' })
|
||||
@ValidateBoolean()
|
||||
enabled!: boolean;
|
||||
|
||||
@IsEnum(ImageFormat)
|
||||
@ApiProperty({ enumName: 'ImageFormat', enum: ImageFormat })
|
||||
@ValidateEnum({ enum: ImageFormat, name: 'ImageFormat' })
|
||||
format!: ImageFormat;
|
||||
|
||||
@IsInt()
|
||||
|
|
@ -600,8 +582,7 @@ export class SystemConfigImageDto {
|
|||
@IsObject()
|
||||
fullsize!: SystemConfigGeneratedFullsizeImageDto;
|
||||
|
||||
@IsEnum(Colorspace)
|
||||
@ApiProperty({ enumName: 'Colorspace', enum: Colorspace })
|
||||
@ValidateEnum({ enum: Colorspace, name: 'Colorspace' })
|
||||
colorspace!: Colorspace;
|
||||
|
||||
@ValidateBoolean()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue