This commit is contained in:
2025-12-27 13:42:50 +01:00
parent c107ec9b5b
commit eed4a0e438
8 changed files with 100 additions and 51 deletions
+12
View File
@@ -0,0 +1,12 @@
"use server";
import axios from "axios";
import { Node } from "@/lib/types";
export async function getDocker(node: Node): Promise<{ version: string }> {
return await (
await axios.get(`http://${node.ip}:3000/api/get-docker`, {
headers: { Authorization: `ApiKey ${node.key}` },
})
).data;
}
-14
View File
@@ -1,14 +0,0 @@
"use server";
import axios from "axios";
export async function getDocker(
node_ip: string,
key: string
): Promise<{ version: string }> {
return await (
await axios.get(`http://${node_ip}:3000/api/get-docker`, {
headers: { Authorization: `ApiKey ${key}` },
})
).data;
}
+32
View File
@@ -0,0 +1,32 @@
"use server";
import { read, write } from "@/app/api/file";
import { Node, NodeLiveData } from "@/lib/types";
import axios from "axios";
export async function getNodes(): Promise<Node[]> {
return await read(() => [], "data", "nodes.json");
}
export async function setNodes(nodes: Node[]) {
await write(nodes, "data", "nodes.json");
}
export async function getNode(node_id: string): Promise<Node | undefined> {
const nodes = await read<Node[]>(() => [], "data", "nodes.json");
return nodes.find((v) => v.node_id === node_id);
}
export async function getLiveNodes(): Promise<NodeLiveData[]> {
const nodes = await read(() => [], "data", "nodes.json");
return await Promise.all(nodes.map(getLiveNode));
}
export async function getLiveNode(node: Node): Promise<NodeLiveData> {
const data = await (
await axios.get(`http://${node.ip}:3000/api/status`, {
headers: { Authorization: `ApiKey ${node.key}` },
})
).data;
return { ...node, liveData: data.liveData };
}