Files
zone/app.js~
2026-02-22 22:10:55 +00:00

119 lines
2.9 KiB
JavaScript

const statusEl = document.getElementById("status");
const healthEl = document.getElementById("health");
const buildBtn = document.getElementById("buildBtn");
const buildResultEl = document.getElementById("buildResult");
async function fetchStatus() {
try {
const res = await fetch("/api/status");
const text = await res.text();
statusEl.textContent = text;
statusEl.className = "badge ok";
} catch {
statusEl.textContent = "ERROR";
statusEl.className = "badge error";
}
}
async function fetchHealth() {
try {
const res = await fetch("/api/health");
const text = await res.text();
healthEl.textContent = text;
healthEl.className = "badge ok";
} catch {
healthEl.textContent = "ERROR";
healthEl.className = "badge error";
}
}
async function runBuild() {
buildBtn.disabled = true;
buildResultEl.textContent = "Running build...";
buildResultEl.className = "muted";
try {
const res = await fetch("/api/build", {
method: "POST"
});
if (!res.ok) {
throw new Error("Build failed");
}
const text = await res.text();
buildResultEl.textContent = text || "Build started successfully";
} catch (err) {
buildResultEl.textContent = "Build failed";
} finally {
buildBtn.disabled = false;
}
}
const logOutput = document.getElementById("logOutput");
function streamLogs() {
const eventSource = new EventSource("/api/build/logs");
eventSource.onmessage = function(event) {
logOutput.textContent += event.data + "\n";
logOutput.scrollTop = logOutput.scrollHeight;
};
eventSource.onerror = function() {
eventSource.close();
};
}
streamLogs();
// Initial load
fetchStatus();
fetchHealth();
// Button handler
buildBtn.addEventListener("click", runBuild);
const orgRoamBtn = document.getElementById("orgRoamBtn");
const orgRoamResult = document.getElementById("orgRoamResult");
const orgRoamLogs = document.getElementById("orgRoamLogs");
let orgRoamEventSource = null;
async function runOrgRoamBuild() {
orgRoamBtn.disabled = true;
orgRoamLogs.textContent = ""; // 🔥 clear logs each run
orgRoamResult.textContent = "Running make...";
try {
const res = await fetch("/api/orgroam/build", { method: "POST" });
if (!res.ok) {
throw new Error("Build failed");
}
orgRoamResult.textContent = "Build started";
if (orgRoamEventSource) {
orgRoamEventSource.close();
}
orgRoamEventSource = new EventSource("/api/orgroam/logs");
orgRoamEventSource.onmessage = function(event) {
orgRoamLogs.textContent += event.data + "\n";
orgRoamLogs.scrollTop = orgRoamLogs.scrollHeight;
};
orgRoamEventSource.onerror = function() {
orgRoamEventSource.close();
};
} catch (err) {
orgRoamResult.textContent = "Build failed";
} finally {
orgRoamBtn.disabled = false;
}
}
orgRoamBtn.addEventListener("click", runOrgRoamBuild);