mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-27 08:50:56 +01:00
* refactor: remove central validation export to improve typescript performance * fix: missing package exports change in validation package * chore: address pull request feedback
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { createCustomErrorParams } from "./form/i18n";
|
|
|
|
export const certificateValidFileNameSchema = z.string().regex(/^[\w\-. ]+$/);
|
|
|
|
export const superRefineCertificateFile = (value: File | null, context: z.RefinementCtx) => {
|
|
if (!value) {
|
|
return context.addIssue({
|
|
code: "invalid_type",
|
|
expected: "object",
|
|
received: "null",
|
|
});
|
|
}
|
|
|
|
const result = certificateValidFileNameSchema.safeParse(value.name);
|
|
if (!result.success) {
|
|
return context.addIssue({
|
|
code: "custom",
|
|
params: createCustomErrorParams({
|
|
key: "invalidFileName",
|
|
params: {},
|
|
}),
|
|
});
|
|
}
|
|
|
|
if (value.type !== "application/x-x509-ca-cert" && value.type !== "application/pkix-cert") {
|
|
return context.addIssue({
|
|
code: "custom",
|
|
params: createCustomErrorParams({
|
|
key: "invalidFileType",
|
|
params: { expected: ".crt" },
|
|
}),
|
|
});
|
|
}
|
|
|
|
if (value.size > 1024 * 1024) {
|
|
return context.addIssue({
|
|
code: "custom",
|
|
params: createCustomErrorParams({
|
|
key: "fileTooLarge",
|
|
params: { maxSize: "1 MB" },
|
|
}),
|
|
});
|
|
}
|
|
|
|
return null;
|
|
};
|