diff --git a/frontend/src/app/json-editor/_components/InstallMethod.tsx b/frontend/src/app/json-editor/_components/InstallMethod.tsx index 8a597c5d0..44318d28d 100644 --- a/frontend/src/app/json-editor/_components/InstallMethod.tsx +++ b/frontend/src/app/json-editor/_components/InstallMethod.tsx @@ -1,12 +1,6 @@ import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { OperatingSystems } from "@/config/siteConfig"; import { PlusCircle, Trash2 } from "lucide-react"; import { memo, useCallback, useRef } from "react"; @@ -20,21 +14,31 @@ type InstallMethodProps = { setZodErrors: (zodErrors: z.ZodError | null) => void; }; -function InstallMethod({ - script, - setScript, - setIsValid, - setZodErrors, -}: InstallMethodProps) { +function InstallMethod({ script, setScript, setIsValid, setZodErrors }: InstallMethodProps) { const cpuRefs = useRef<(HTMLInputElement | null)[]>([]); const ramRefs = useRef<(HTMLInputElement | null)[]>([]); const hddRefs = useRef<(HTMLInputElement | null)[]>([]); const addInstallMethod = useCallback(() => { setScript((prev) => { + const { type, slug } = prev; + const newMethodType = "default"; + + let scriptPath = ""; + + if (type === "pve") { + scriptPath = `tools/pve/${slug}.sh`; + } else if (type === "addon") { + scriptPath = `tools/addon/${slug}.sh`; + } else if (newMethodType === "alpine") { + scriptPath = `${type}/alpine-${slug}.sh`; + } else { + scriptPath = `${type}/${slug}.sh`; + } + const method = InstallMethodSchema.parse({ - type: "default", - script: `${prev.type}/${prev.slug}.sh`, + type: newMethodType, + script: scriptPath, resources: { cpu: null, ram: null, @@ -43,6 +47,7 @@ function InstallMethod({ version: null, }, }); + return { ...prev, install_methods: [...prev.install_methods, method], @@ -63,9 +68,7 @@ function InstallMethod({ if (key === "type") { updatedMethod.script = - value === "alpine" - ? `${prev.type}/alpine-${prev.slug}.sh` - : `${prev.type}/${prev.slug}.sh`; + value === "alpine" ? `${prev.type}/alpine-${prev.slug}.sh` : `${prev.type}/${prev.slug}.sh`; // Set OS to Alpine and reset version if type is alpine if (value === "alpine") { @@ -112,10 +115,7 @@ function InstallMethod({

Install Methods

{script.install_methods.map((method, index) => (
- updateInstallMethod(index, "type", value)}> @@ -205,9 +205,7 @@ function InstallMethod({ - {OperatingSystems.find( - (os) => os.name === method.resources.os, - )?.versions.map((version) => ( + {OperatingSystems.find((os) => os.name === method.resources.os)?.versions.map((version) => ( {version.name} @@ -215,22 +213,12 @@ function InstallMethod({
- ))} - diff --git a/frontend/src/app/json-editor/page.tsx b/frontend/src/app/json-editor/page.tsx index fc99f2a98..1789b0a29 100644 --- a/frontend/src/app/json-editor/page.tsx +++ b/frontend/src/app/json-editor/page.tsx @@ -60,14 +60,25 @@ export default function JSONGenerator() { setScript((prev) => { const updated = { ...prev, [key]: value }; - if (key === "type" || key === "slug") { - updated.install_methods = updated.install_methods.map((method) => ({ - ...method, - script: - method.type === "alpine" - ? `${updated.type}/alpine-${updated.slug}.sh` - : `${updated.type}/${updated.slug}.sh`, - })); + if (updated.slug && updated.type) { + updated.install_methods = updated.install_methods.map((method) => { + let scriptPath = ""; + + if (updated.type === "pve") { + scriptPath = `tools/pve/${updated.slug}.sh`; + } else if (updated.type === "addon") { + scriptPath = `tools/addon/${updated.slug}.sh`; + } else if (method.type === "alpine") { + scriptPath = `${updated.type}/alpine-${updated.slug}.sh`; + } else { + scriptPath = `${updated.type}/${updated.slug}.sh`; + } + + return { + ...method, + script: scriptPath, + }; + }); } const result = ScriptSchema.safeParse(updated);