Export InstallMethodSchema and integrate into JSONGenerator for better validation of install method data input

This commit is contained in:
Bram Suurd 2024-11-13 23:50:04 +01:00
parent 1b7f14b224
commit 8afa8e9e09
2 changed files with 4 additions and 14 deletions

View File

@ -1,6 +1,6 @@
import { z } from "zod";
const InstallMethodSchema = z.object({
export const InstallMethodSchema = z.object({
type: z.enum(["default", "alpine"], {
errorMap: () => ({ message: "Type must be either 'default' or 'alpine'" })
}),

View File

@ -24,7 +24,7 @@ import { z } from "zod";
import { format } from "date-fns";
import { Label } from "@/components/ui/label";
import { AlertColors } from "@/config/siteConfig";
import { ScriptSchema } from "./_schemas/schemas";
import { InstallMethodSchema, ScriptSchema } from "./_schemas/schemas";
type Script = z.infer<typeof ScriptSchema>;
@ -91,17 +91,7 @@ export default function JSONGenerator() {
const addInstallMethod = () => {
setScript((prev) => {
const method: {
type: "default" | "alpine";
script: string;
resources: {
cpu: number | null;
ram: number | null;
hdd: number | null;
os: string | null;
version: number | null;
};
} = {
const method = InstallMethodSchema.parse({
type: "default",
script: `/${prev.type}/${prev.slug}.sh`,
resources: {
@ -111,7 +101,7 @@ export default function JSONGenerator() {
os: null,
version: null,
},
};
});
return {
...prev,
install_methods: [...prev.install_methods, method],