mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-15 12:19:17 +00:00
Refactor JSON schema handling: move schema definitions to separate file
This commit is contained in:
parent
49dedd8430
commit
0dc75b1562
39
frontend/src/app/json-editor/_schemas/schemas.ts
Normal file
39
frontend/src/app/json-editor/_schemas/schemas.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const InstallMethodSchema = z.object({
|
||||||
|
type: z.enum(["default", "alpine"]),
|
||||||
|
script: z.string().min(1),
|
||||||
|
resources: z.object({
|
||||||
|
cpu: z.number().nullable(),
|
||||||
|
ram: z.number().nullable(),
|
||||||
|
hdd: z.number().nullable(),
|
||||||
|
os: z.string().nullable(),
|
||||||
|
version: z.number().nullable(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const NoteSchema = z.object({
|
||||||
|
text: z.string().min(1),
|
||||||
|
type: z.string().min(1),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const ScriptSchema = z.object({
|
||||||
|
name: z.string().min(1),
|
||||||
|
slug: z.string().min(1),
|
||||||
|
categories: z.array(z.number()),
|
||||||
|
date_created: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
||||||
|
type: z.enum(["vm", "ct", "misc"]),
|
||||||
|
updateable: z.boolean(),
|
||||||
|
privileged: z.boolean(),
|
||||||
|
interface_port: z.number().nullable(),
|
||||||
|
documentation: z.string().nullable(),
|
||||||
|
website: z.string().url().nullable(),
|
||||||
|
logo: z.string().url().nullable(),
|
||||||
|
description: z.string().min(1),
|
||||||
|
install_methods: z.array(InstallMethodSchema),
|
||||||
|
default_credentials: z.object({
|
||||||
|
username: z.string().nullable(),
|
||||||
|
password: z.string().nullable(),
|
||||||
|
}),
|
||||||
|
notes: z.array(NoteSchema),
|
||||||
|
});
|
@ -24,44 +24,7 @@ import { z } from "zod";
|
|||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { AlertColors } from "@/config/siteConfig";
|
import { AlertColors } from "@/config/siteConfig";
|
||||||
|
import { ScriptSchema } from "./_schemas/schemas";
|
||||||
const InstallMethodSchema = z.object({
|
|
||||||
type: z.enum(["default", "alpine"]),
|
|
||||||
script: z.string().min(1),
|
|
||||||
resources: z.object({
|
|
||||||
cpu: z.number().nullable(),
|
|
||||||
ram: z.number().nullable(),
|
|
||||||
hdd: z.number().nullable(),
|
|
||||||
os: z.string().nullable(),
|
|
||||||
version: z.number().nullable(),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const NoteSchema = z.object({
|
|
||||||
text: z.string().min(1),
|
|
||||||
type: z.string().min(1),
|
|
||||||
});
|
|
||||||
|
|
||||||
const ScriptSchema = z.object({
|
|
||||||
name: z.string().min(1),
|
|
||||||
slug: z.string().min(1),
|
|
||||||
categories: z.array(z.number()),
|
|
||||||
date_created: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
||||||
type: z.enum(["vm", "ct", "misc"]),
|
|
||||||
updateable: z.boolean(),
|
|
||||||
privileged: z.boolean(),
|
|
||||||
interface_port: z.number().nullable(),
|
|
||||||
documentation: z.string().nullable(),
|
|
||||||
website: z.string().url().nullable(),
|
|
||||||
logo: z.string().url().nullable(),
|
|
||||||
description: z.string().min(1),
|
|
||||||
install_methods: z.array(InstallMethodSchema),
|
|
||||||
default_credentials: z.object({
|
|
||||||
username: z.string().nullable(),
|
|
||||||
password: z.string().nullable(),
|
|
||||||
}),
|
|
||||||
notes: z.array(NoteSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
type Script = z.infer<typeof ScriptSchema>;
|
type Script = z.infer<typeof ScriptSchema>;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user