mirror of
https://github.com/diced/zipline.git
synced 2026-07-08 20:57:11 -07:00
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import z from 'zod';
|
|
import { sanitizeFilename } from './fs';
|
|
|
|
export function zValidatePath(val: string | undefined, ctx: z.RefinementCtx) {
|
|
if (!val) return;
|
|
|
|
const sanitized = sanitizeFilename(val);
|
|
if (!sanitized) {
|
|
ctx.addIssue({
|
|
code: 'custom',
|
|
message: 'Invalid path',
|
|
input: val,
|
|
});
|
|
|
|
return undefined;
|
|
}
|
|
|
|
return sanitized;
|
|
}
|
|
|
|
export const zStringTrimmed = z.string().trim().min(1);
|
|
|
|
export const zQsBoolean = z.enum(['true', 'false']).transform((val) => val === 'true');
|
|
|
|
export const paginationQs = z.object({
|
|
page: z.coerce.number(),
|
|
perpage: z.coerce.number().default(15),
|
|
filter: z.enum(['dashboard', 'none', 'all']).optional().default('none'),
|
|
favorite: zQsBoolean.default(false).optional(),
|
|
sortBy: z
|
|
.enum([
|
|
'id',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'deletesAt',
|
|
'name',
|
|
'originalName',
|
|
'size',
|
|
'type',
|
|
'views',
|
|
'favorite',
|
|
])
|
|
.optional()
|
|
.default('createdAt'),
|
|
order: z.enum(['asc', 'desc']).optional().default('desc'),
|
|
});
|