Commit 8f067d87 authored by zk's avatar zk
Browse files

Support older Node runtime

parent b7dc9daa
const http = require("node:http");
const fs = require("node:fs");
const path = require("node:path");
const { spawn } = require("node:child_process");
const { randomUUID } = require("node:crypto");
const http = require("http");
const fs = require("fs");
const path = require("path");
const { spawn } = require("child_process");
const crypto = require("crypto");
const PORT = Number(process.env.PORT || 3066);
const POLL_INTERVAL_MS = Number(process.env.POLL_INTERVAL_MS || 10000);
......@@ -27,6 +27,13 @@ let lastRefresh = null;
let refreshInFlight = null;
let refreshInFlightIncludesModels = false;
function createId() {
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
return [4, 2, 2, 2, 6]
.map((bytes) => crypto.randomBytes(bytes).toString("hex"))
.join("-");
}
function ensureDataFile() {
if (!fs.existsSync(DATA_DIR)) {
fs.mkdirSync(DATA_DIR, { recursive: true });
......@@ -73,7 +80,7 @@ function normalizeServer(input) {
.slice(0, 6);
return {
id: String(input.id || randomUUID()),
id: String(input.id || createId()),
name,
host,
port: clampInt(input.port, 1, 65535, 22),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment