From 61a9e1d8d99e446bc496b298f8f332699c09e69f Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 3 Jan 2026 20:01:42 +0100 Subject: [PATCH] Register application --- src/app/applications/page.tsx | 13 +-- src/app/overview/page.tsx | 6 +- ...InstallApplication.tsx => RegisterApp.tsx} | 28 ++---- src/lib/dockship/application.ts | 86 +++++++++++-------- src/lib/types.ts | 1 - 5 files changed, 62 insertions(+), 72 deletions(-) rename src/components/dialogs/{InstallApplication.tsx => RegisterApp.tsx} (66%) diff --git a/src/app/applications/page.tsx b/src/app/applications/page.tsx index c61e2f9..041c584 100644 --- a/src/app/applications/page.tsx +++ b/src/app/applications/page.tsx @@ -12,7 +12,7 @@ import { import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { MoreVertical, Plus, Rocket } from "lucide-react"; -import InstallApplicationDialog from "@/components/dialogs/InstallApplication"; +import RegisterAppDialog from "@/components/dialogs/RegisterApp"; import { getApps, removeApp } from "@/lib/dockship/application"; import RemoveDialog from "@/components/dialogs/Remove"; import DeployAppDialog from "@/components/dialogs/DeployApp"; @@ -31,17 +31,20 @@ export default function ApplicationsPage() { }; return ( - + {/* Header */}
{apps.length} apps
- + - +
{apps.map((app) => ( diff --git a/src/app/overview/page.tsx b/src/app/overview/page.tsx index 97c3074..b20c6f0 100644 --- a/src/app/overview/page.tsx +++ b/src/app/overview/page.tsx @@ -131,13 +131,9 @@ export default function OverviewPage() { {app.name}
-
+
{app.deployments.length}
- -
- {nodes.find((n) => n.node_id === app.nodeId)?.name ?? "—"} -
)) )} diff --git a/src/components/dialogs/InstallApplication.tsx b/src/components/dialogs/RegisterApp.tsx similarity index 66% rename from src/components/dialogs/InstallApplication.tsx rename to src/components/dialogs/RegisterApp.tsx index 9abb5c9..955914e 100644 --- a/src/components/dialogs/InstallApplication.tsx +++ b/src/components/dialogs/RegisterApp.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, ReactNode, useEffect } from "react"; +import { useState, ReactNode } from "react"; import { Button } from "@/components/ui/button"; import { Dialog, @@ -15,22 +15,19 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { getLiveNodes } from "@/lib/dockship/node"; import { Combobox } from "../ui/combobox"; -import { Node, NodeLiveData } from "@/lib/types"; -import { installApp } from "@/lib/dockship/application"; +import { registerApp } from "@/lib/dockship/application"; import { useAsync } from "@/hooks/use-async"; -export default function InstallApplicationDialog({ +export default function RegisterAppDialog({ children, }: { children: ReactNode; }) { - const { value: nodes } = useAsync([], getLiveNodes); const [name, setName] = useState(""); const [repo, setRepo] = useState(""); - const [node, setNode] = useState(""); const deploy = async () => { - console.log(await installApp(name, repo, node)); + console.log(await registerApp(name, repo)); }; return ( @@ -39,7 +36,7 @@ export default function InstallApplicationDialog({ - Install Application + Register Application
@@ -66,21 +63,6 @@ export default function InstallApplicationDialog({ placeholder="https://github.com/me/myrepo.git" />
- -
- - node.liveData) - .map((node) => ({ label: node.name, value: node.node_id }))} - placeholder="Select Node..." - listPlaceholder="No nodes found :(" - /> -
diff --git a/src/lib/dockship/application.ts b/src/lib/dockship/application.ts index db7c4a4..c7049c3 100644 --- a/src/lib/dockship/application.ts +++ b/src/lib/dockship/application.ts @@ -1,30 +1,9 @@ "use server"; import { verifySession } from "../../core/auth/session"; -import { getNodes } from "@/lib/dockship/node"; -import axios from "axios"; import { Env, EnvVariable, Application } from "@/lib/types"; import { read, write } from "@/app/api/file"; - -export async function installApp(name: string, repo: string, nodeId: string) { - if (await verifySession()) { - throw new Error("Unauthorized"); - } - - const nodes = await getNodes(); - - const targetNode = nodes.find((node) => node.node_id === nodeId); - - return await ( - await axios.post( - `http://${targetNode?.ip}:3000/api/applications`, - { name, repo, nodeId }, - { - headers: { Authorization: `ApiKey ${targetNode?.key}` }, - } - ) - ).data.apps; -} +import { randomUUID } from "crypto"; export async function getApps(): Promise { if (await verifySession()) { @@ -34,7 +13,54 @@ export async function getApps(): Promise { return read(() => [], "data", "apps.json"); } +export async function registerApp(name: string, repo: string) { + if (await verifySession()) { + throw new Error("Unauthorized"); + } + + const app: Application = { + id: randomUUID(), + name, + repo, + createdAt: new Date().toISOString(), + deployments: [], + env: {}, + }; + + await write([...(await getApps()), app], "data", "apps.json"); + + return app; +} + +export async function removeApp(appId: string) { + if (await verifySession()) { + throw new Error("Unauthorized"); + } + + const apps = await getApps(); + + const nextApps = apps.filter((app) => app.id !== appId); + + await write(nextApps, "data", "apps.json"); +} + +export async function editApp(appId: string, updatedApp: Application) { + if (await verifySession()) { + throw new Error("Unauthorized"); + } + + const apps = await getApps(); + + const nextApps = apps.map((app) => (app.id === appId ? updatedApp : app)); + + await write(nextApps, "data", "apps.json"); +} + export async function getEnv(): Promise> { + if (await verifySession()) { + throw new Error("Unauthorized"); + } + const apps = await getApps(); return apps.reduce>((acc, app) => { @@ -61,19 +87,3 @@ export async function setEnv( if (!app) throw new Error("App not found"); editApp(appId, { ...app, env: variables }); } - -export async function removeApp(appId: string) { - const apps = await getApps(); - - const nextApps = apps.filter((app) => app.id !== appId); - - await write(nextApps, "data", "apps.json"); -} - -export async function editApp(appId: string, updatedApp: Application) { - const apps = await getApps(); - - const nextApps = apps.map((app) => (app.id === appId ? updatedApp : app)); - - await write(nextApps, "data", "apps.json"); -} diff --git a/src/lib/types.ts b/src/lib/types.ts index 7853d2d..3642591 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -52,7 +52,6 @@ export interface Application { id: string; name: string; repo: string; - nodeId: string; createdAt: string; deployments: string[]; env: Record;