mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
refactor(server): use zod time validation (#29189)
This commit is contained in:
parent
83091d2834
commit
09d0380804
6 changed files with 11 additions and 11 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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": {
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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',
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -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'),
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue