refactor(server): use zod time validation (#29189)

This commit is contained in:
Timon 2026-06-18 13:56:02 +02:00 committed by GitHub
parent 83091d2834
commit 09d0380804
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 11 additions and 11 deletions

View file

@ -33,7 +33,7 @@ class SystemConfigNightlyTasksDto {
/// Missing thumbnails /// Missing thumbnails
bool missingThumbnails; bool missingThumbnails;
/// Start time /// Start time (HH:MM)
String startTime; String startTime;
/// Sync quota usage /// Sync quota usage

View file

@ -26144,8 +26144,8 @@
"type": "boolean" "type": "boolean"
}, },
"startTime": { "startTime": {
"description": "Start time", "description": "Start time (HH:MM)",
"pattern": "^([01]\\d|2[0-3]):[0-5]\\d$", "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$",
"type": "string" "type": "string"
}, },
"syncQuotaUsage": { "syncQuotaUsage": {

View file

@ -2501,7 +2501,7 @@ export type SystemConfigNightlyTasksDto = {
generateMemories: boolean; generateMemories: boolean;
/** Missing thumbnails */ /** Missing thumbnails */
missingThumbnails: boolean; missingThumbnails: boolean;
/** Start time */ /** Start time (HH:MM) */
startTime: string; startTime: string;
/** Sync quota usage */ /** Sync quota usage */
syncQuotaUsage: boolean; syncQuotaUsage: boolean;

View file

@ -70,7 +70,7 @@ describe(SystemConfigController.name, () => {
errorDto.validationError([ errorDto.validationError([
{ {
path: ['nightlyTasks', 'startTime'], path: ['nightlyTasks', 'startTime'],
message: 'Invalid input: expected string in HH:mm format, received string', message: 'Invalid input: expected string in HH:MM format, received string',
}, },
]), ]),
); );

View file

@ -20,7 +20,6 @@ import {
VideoCodecSchema, VideoCodecSchema,
VideoContainerSchema, VideoContainerSchema,
} from 'src/enum'; } from 'src/enum';
import { isValidTime } from 'src/validation';
import z from 'zod'; import z from 'zod';
/** Coerces 'true'/'false' strings to boolean, but also allows booleans. */ /** Coerces 'true'/'false' strings to boolean, but also allows booleans. */
@ -204,7 +203,12 @@ const SystemConfigNewVersionCheckSchema = z
const SystemConfigNightlyTasksSchema = z const SystemConfigNightlyTasksSchema = z
.object({ .object({
startTime: isValidTime.describe('Start time'), startTime: z.iso
.time({
precision: -1,
error: (iss) => `Invalid input: expected string in HH:MM format, received ${typeof iss.input}`,
})
.describe('Start time (HH:MM)'),
databaseCleanup: configBool.describe('Database cleanup'), databaseCleanup: configBool.describe('Database cleanup'),
missingThumbnails: configBool.describe('Missing thumbnails'), missingThumbnails: configBool.describe('Missing thumbnails'),
clusterNewFaces: configBool.describe('Cluster new faces'), clusterNewFaces: configBool.describe('Cluster new faces'),

View file

@ -188,10 +188,6 @@ export const isoDateToDate = z
) )
.meta({ example: '2024-01-01' }); .meta({ example: '2024-01-01' });
export const isValidTime = z
.string()
.regex(/^([01]\d|2[0-3]):[0-5]\d$/, 'Invalid input: expected string in HH:mm format, received string');
/** /**
* Latitude in range [-90, 90]. Reuse for body or query params. * Latitude in range [-90, 90]. Reuse for body or query params.
* *