Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/ai-music-system / status.js |
| Date | Not specified in source |
| Repository | Janady13/ai-music-system |
| Revision | 9a816470ef81edba7a5d8f3aae62c05eead638a7 |
| Branch | main |
| Path or archive member | status.js |
| Original SHA-256 | 5d6148b3462c612cfd286510630feb41aacc6e94fd81edb20a2334e861805400 |
| Git blob SHA | 2a6c5498c47a4f84d2350417cc60f38bc4aad239 |
| Reading-copy SHA-256 | 5d6148b3462c612cfd286510630feb41aacc6e94fd81edb20a2334e861805400 |
Every recorded occurrence
These 3 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/ai-music-system / status.js | main | 9a816470ef81edba7a5d8f3aae62c05eead638a7 | Open original |
| Janady13/ai-music-system / status.js | codex/create-ai-for-music-generation-ifwcfc | cd5207850253ee238f8a267c043b1e3c070ed81a | Open original |
| Janady13/ai-music-system / status.js | codex/create-ai-for-music-generation | 017052c0e72c6175378aebb7a7f9dd96e82c3ce2 | Open original |
Recovered source transcript
Download complete source text ↓89 lines · 2.7 KB
const http = require("http");
const os = require("os");
const fs = require("fs");
const path = require("path");
const { read } = require("./lib/state");
const TOKEN = process.env.STATUS_TOKEN || "";
const PORT = Number(process.env.PORT || process.env.STATUS_PORT || 0);
function okAuth(req) {
if (!TOKEN) return false;
const h = req.headers["authorization"] || "";
const bearer = h.startsWith("Bearer ") ? h.slice(7) : "";
const url = new URL(req.url, "http://x");
const q = url.searchParams.get("token") || "";
return bearer === TOKEN || q === TOKEN;
}
function fmt(ts) {
if (!ts) return "never";
const d = new Date(ts);
return d.toLocaleString();
}
const server = http.createServer((req, res) => {
if (req.method === "GET" && req.url === "/health") {
res.writeHead(200, { "Content-Type": "application/json" });
return res.end(JSON.stringify({ ok: true }));
}
if (!okAuth(req)) {
res.writeHead(401, { "Content-Type": "application/json" });
return res.end(JSON.stringify({ error: "unauthorized" }));
}
if (req.method === "GET" && (req.url.startsWith("/api/status"))) {
const s = read();
res.writeHead(200, {
"Content-Type": "application/json",
"Cache-Control": "no-store",
"Access-Control-Allow-Origin": "*"
});
return res.end(JSON.stringify({
host: os.hostname(),
uptimeSec: Math.floor(process.uptime()),
data: s
}));
}
if (req.method === "GET" && (req.url === "/status" || req.url === "/")) {
const s = read();
const keys = Object.keys(s).sort();
let rows = "";
for (const k of keys) rows += `<tr><td>${k}</td><td>${fmt(s[k])}</td></tr>`;
const html = `<!doctype html>
<html><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>skynet status</title>
<style>
body{font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Arial;max-width:900px;margin:24px auto;padding:12px}
h1{font-size:22px;margin:0 0 12px}
table{width:100%;border-collapse:collapse}
td,th{border:1px solid #ddd;padding:8px;font-size:14px}
tr:nth-child(even){background:#fafafa}
small{color:#666}
</style>
</head>
<body>
<h1>skynet status</h1>
<small>host ${os.hostname()} uptime ${Math.floor(process.uptime())}s</small>
<table>
<tr><th>key</th><th>time</th></tr>
${rows}
</table>
</body></html>`;
res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-store" });
return res.end(html);
}
res.writeHead(404);
res.end("not found");
});
server.listen(PORT, "0.0.0.0", () => {
const addr = server.address();
const port = typeof addr === "object" && addr ? addr.port : 0;
console.log("status up on port", port);
try { fs.writeFileSync(path.join(os.homedir(), ".skynet_status_port"), String(port)); } catch {}
});