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

Support older Node runtime

parent b7dc9daa
const http = require("node:http"); const http = require("http");
const fs = require("node:fs"); const fs = require("fs");
const path = require("node:path"); const path = require("path");
const { spawn } = require("node:child_process"); const { spawn } = require("child_process");
const { randomUUID } = require("node:crypto"); const crypto = require("crypto");
const PORT = Number(process.env.PORT || 3066); const PORT = Number(process.env.PORT || 3066);
const POLL_INTERVAL_MS = Number(process.env.POLL_INTERVAL_MS || 10000); const POLL_INTERVAL_MS = Number(process.env.POLL_INTERVAL_MS || 10000);
...@@ -27,6 +27,13 @@ let lastRefresh = null; ...@@ -27,6 +27,13 @@ let lastRefresh = null;
let refreshInFlight = null; let refreshInFlight = null;
let refreshInFlightIncludesModels = false; 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() { function ensureDataFile() {
if (!fs.existsSync(DATA_DIR)) { if (!fs.existsSync(DATA_DIR)) {
fs.mkdirSync(DATA_DIR, { recursive: true }); fs.mkdirSync(DATA_DIR, { recursive: true });
...@@ -73,7 +80,7 @@ function normalizeServer(input) { ...@@ -73,7 +80,7 @@ function normalizeServer(input) {
.slice(0, 6); .slice(0, 6);
return { return {
id: String(input.id || randomUUID()), id: String(input.id || createId()),
name, name,
host, host,
port: clampInt(input.port, 1, 65535, 22), 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