Node data
This commit is contained in:
+15
-6
@@ -1,7 +1,7 @@
|
||||
"use server";
|
||||
|
||||
import { read, write } from "@/app/api/file";
|
||||
import { Node, NodeLiveData } from "@/lib/types";
|
||||
import { Docker, Node, NodeLiveData } from "@/lib/types";
|
||||
import axios from "axios";
|
||||
|
||||
export async function getNodes(): Promise<Node[]> {
|
||||
@@ -17,11 +17,6 @@ export async function getNode(node_id: string): Promise<Node | undefined> {
|
||||
return nodes.find((v) => v.node_id === node_id);
|
||||
}
|
||||
|
||||
export async function getLiveNodes(): Promise<(NodeLiveData & Node)[]> {
|
||||
const nodes = await read(() => [], "data", "nodes.json");
|
||||
return await Promise.all(nodes.map(getLiveNode));
|
||||
}
|
||||
|
||||
export async function getLiveNode(node: Node): Promise<NodeLiveData & Node> {
|
||||
const data = await (
|
||||
await axios.get(`http://${node.ip}:3000/api/status`, {
|
||||
@@ -30,3 +25,17 @@ export async function getLiveNode(node: Node): Promise<NodeLiveData & Node> {
|
||||
).data;
|
||||
return { ...node, liveData: data.liveData };
|
||||
}
|
||||
|
||||
export async function getLiveNodes(): Promise<(NodeLiveData & Node)[]> {
|
||||
const nodes = await read(() => [], "data", "nodes.json");
|
||||
return await Promise.all(nodes.map(getLiveNode));
|
||||
}
|
||||
|
||||
export async function getDockerNode(node: Node): Promise<Docker> {
|
||||
const data = await (
|
||||
await axios.get(`http://${node.ip}:3000/api/get-docker`, {
|
||||
headers: { Authorization: `ApiKey ${node.key}` },
|
||||
})
|
||||
).data;
|
||||
return { ...node, containers: data.containers, version: data.version };
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,6 +6,6 @@ const docker = new Docker();
|
||||
|
||||
export async function getDocker() {
|
||||
const version = await docker.version();
|
||||
console.log("Docker version:", version);
|
||||
return version;
|
||||
const containers = await docker.listContainers();
|
||||
return { version, containers };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user