mirror of
https://github.com/immich-app/immich.git
synced 2026-06-27 22:35:57 +00:00
refactor(server): use zod time validation (#29189)
This commit is contained in:
@@ -33,7 +33,7 @@ class SystemConfigNightlyTasksDto {
|
||||
/// Missing thumbnails
|
||||
bool missingThumbnails;
|
||||
|
||||
/// Start time
|
||||
/// Start time (HH:MM)
|
||||
String startTime;
|
||||
|
||||
/// Sync quota usage
|
||||
|
||||
@@ -26144,8 +26144,8 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"startTime": {
|
||||
"description": "Start time",
|
||||
"pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
|
||||
"description": "Start time (HH:MM)",
|
||||
"pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$",
|
||||
"type": "string"
|
||||
},
|
||||
"syncQuotaUsage": {
|
||||
|
||||
@@ -2501,7 +2501,7 @@ export type SystemConfigNightlyTasksDto = {
|
||||
generateMemories: boolean;
|
||||
/** Missing thumbnails */
|
||||
missingThumbnails: boolean;
|
||||
/** Start time */
|
||||
/** Start time (HH:MM) */
|
||||
startTime: string;
|
||||
/** Sync quota usage */
|
||||
syncQuotaUsage: boolean;
|
||||
|
||||
@@ -70,7 +70,7 @@ describe(SystemConfigController.name, () => {
|
||||
errorDto.validationError([
|
||||
{
|
||||
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',
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
VideoCodecSchema,
|
||||
VideoContainerSchema,
|
||||
} from 'src/enum';
|
||||
import { isValidTime } from 'src/validation';
|
||||
import z from 'zod';
|
||||
|
||||
/** Coerces 'true'/'false' strings to boolean, but also allows booleans. */
|
||||
@@ -204,7 +203,12 @@ const SystemConfigNewVersionCheckSchema = z
|
||||
|
||||
const SystemConfigNightlyTasksSchema = z
|
||||
.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'),
|
||||
missingThumbnails: configBool.describe('Missing thumbnails'),
|
||||
clusterNewFaces: configBool.describe('Cluster new faces'),
|
||||
|
||||
@@ -188,10 +188,6 @@ export const isoDateToDate = z
|
||||
)
|
||||
.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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user