This commit is contained in:
2025-12-27 02:14:28 +01:00
parent ee29c6d9cb
commit 70b0645093
3 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ import { promises as fs } from "fs";
import path from "path"; import path from "path";
export async function read<T extends object>( export async function read<T extends object>(
template: T, template: () => T,
fp: string, fp: string,
...filePaths: string[] ...filePaths: string[]
): Promise<T> { ): Promise<T> {
+3 -4
View File
@@ -1,11 +1,10 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { version } from "../../../package.json"; import { version } from "../../../package.json";
import { read } from "./file"; import { read } from "./file";
import { randomUUID } from "crypto"; import { NodeJsonTemplate } from "./types";
const TEMPLATE = { node_id: randomUUID() };
export async function GET(req: NextRequest): Promise<NextResponse> { export async function GET(req: NextRequest): Promise<NextResponse> {
const { node_id } = await read(TEMPLATE, "data", "node.json"); const { node_id } = await read(NodeJsonTemplate, "data", "node.json");
return NextResponse.json({ app: "dockship", version, node_id }); return NextResponse.json({ app: "dockship", version, node_id });
} }
+11
View File
@@ -0,0 +1,11 @@
import { randomBytes, randomUUID } from "crypto";
export interface NodeJson {
node_id: string;
key: string;
}
export const NodeJsonTemplate: () => NodeJson = () => ({
node_id: randomUUID(),
key: randomBytes(20).toString("base64"),
});