fix windows/linux get system uuid error

This commit is contained in:
musistudio
2025-08-12 21:41:42 +08:00
parent 075ec76ec1
commit cce1625534
7 changed files with 43 additions and 216 deletions

View File

@@ -1,8 +1,6 @@
import Server from "@musistudio/llms";
import { readConfigFile, writeConfigFile } from "./utils";
import { CONFIG_FILE } from "./constants";
import { readConfigFile, writeConfigFile, backupConfigFile } from "./utils";
import { join } from "path";
import { readFileSync } from "fs";
import fastifyStatic from "@fastify/static";
export const createServer = (config: any): Server => {
@@ -10,16 +8,6 @@ export const createServer = (config: any): Server => {
// Add endpoint to read config.json with access control
server.app.get("/api/config", async (req, reply) => {
// Get access level from request (set by auth middleware)
const accessLevel = (req as any).accessLevel || "restricted";
// If restricted access, return 401
if (accessLevel === "restricted") {
reply.status(401).send("API key required to access configuration");
return;
}
// For full access (including temp API key), return complete config
return await readConfigFile();
});
@@ -37,38 +25,17 @@ export const createServer = (config: any): Server => {
// Add endpoint to save config.json with access control
server.app.post("/api/config", async (req, reply) => {
// Only allow full access users to save config
const accessLevel = (req as any).accessLevel || "restricted";
if (accessLevel !== "full") {
reply.status(403).send("Full access required to modify configuration");
return;
}
const newConfig = req.body;
// Backup existing config file if it exists
const { backupConfigFile } = await import("./utils");
const backupPath = await backupConfigFile();
if (backupPath) {
console.log(`Backed up existing configuration file to ${backupPath}`);
}
await writeConfigFile(newConfig);
return { success: true, message: "Config saved successfully" };
});
// Add endpoint for testing full access without modifying config
server.app.post("/api/config/test", async (req, reply) => {
// Only allow full access users to test config access
const accessLevel = (req as any).accessLevel || "restricted";
if (accessLevel !== "full") {
reply.status(403).send("Full access required to test configuration access");
return;
}
// Return success without modifying anything
return { success: true, message: "Access granted" };
});
// Add endpoint to restart the service with access control
server.app.post("/api/restart", async (req, reply) => {
@@ -78,13 +45,16 @@ export const createServer = (config: any): Server => {
reply.status(403).send("Full access required to restart service");
return;
}
reply.send({ success: true, message: "Service restart initiated" });
// Restart the service after a short delay to allow response to be sent
setTimeout(() => {
const { spawn } = require("child_process");
spawn(process.execPath, [process.argv[1], "restart"], { detached: true, stdio: "ignore" });
spawn(process.execPath, [process.argv[1], "restart"], {
detached: true,
stdio: "ignore",
});
}, 1000);
});