Files
OE6DXD e1a4ce0b8b initialize generic rms-software repository
Add the reusable RMS core application (server, web UI, plugins, tests, tools) with generic defaults, GPL licensing, and maintainer context documentation so deployments can consume this repo as software source independent of station-specific overlays.
2026-03-16 03:31:08 +01:00

71 lines
1.7 KiB
JavaScript

const fs = require("fs");
async function createPlugin(ctx) {
return {
async execute(action) {
if (action === "runCheck") {
return runCheck(ctx);
}
throw new Error(`Unknown action: ${action}`);
},
async getStatus() {
return readStatus(ctx);
},
async health() {
return { ok: true };
}
};
}
async function runCheck(ctx) {
const command = String(ctx.getSetting("checkCommand", ctx.env.VSWR_CHECK_CMD || "")).trim();
if (!command) {
return {
ok: true,
skipped: true,
message: "VSWR_CHECK_CMD nicht gesetzt"
};
}
const simulate = typeof ctx.simulateHardware === "boolean"
? ctx.simulateHardware
: (process.platform !== "linux" && String(ctx.env.ALLOW_NON_LINUX_CMDS || "false") !== "true");
if (simulate) {
return {
ok: true,
skipped: true,
message: `VSWR Check simuliert (${ctx.execMode || "dev"})`,
status: readStatus(ctx)
};
}
const result = await ctx.commandRunner(command, {
timeoutMs: Number(ctx.getSetting("timeoutMs", ctx.env.VSWR_CHECK_TIMEOUT_MS || 240000))
});
if (!result.ok) {
throw new Error(result.stderr || result.error || "VSWR check failed");
}
return {
ok: true,
message: "VSWR check abgeschlossen",
status: readStatus(ctx)
};
}
function readStatus(ctx) {
const metadataPath = String(ctx.getSetting("metadataPath", ctx.env.VSWR_METADATA_PATH || "")).trim();
if (!metadataPath || !fs.existsSync(metadataPath)) {
return {
status: "UNKNOWN",
path: metadataPath || null
};
}
const raw = fs.readFileSync(metadataPath, "utf8").trim();
return {
status: raw || "UNKNOWN",
path: metadataPath
};
}
module.exports = {
createPlugin
};