feat: add /sub/clash/latest and /sub/singbox/latest public subscription APIs and display them on the web dashboard UI

This commit is contained in:
jocayn
2026-06-13 17:54:46 +08:00
parent 7d561e0c6b
commit 807b765e2c
3 changed files with 181 additions and 0 deletions
+58
View File
@@ -707,6 +707,64 @@ function startServer() {
const parsedUrl = new URL(req.url, `http://${req.headers.host}`);
const pathname = parsedUrl.pathname;
if (pathname === '/sub/clash/latest' && req.method === 'GET') {
const filePath = path.join(outDir, 'CatMata-sub.yaml');
if (fs.existsSync(filePath)) {
res.writeHead(200, {
'Content-Type': 'text/yaml; charset=utf-8',
'Cache-Control': 'no-store',
'Access-Control-Allow-Origin': '*'
});
res.end(fs.readFileSync(filePath));
} else {
const history = getHistoryList();
if (history.length > 0 && history[0].yamlFile) {
const histPath = path.join(outDir, 'history', history[0].yamlFile);
if (fs.existsSync(histPath)) {
res.writeHead(200, {
'Content-Type': 'text/yaml; charset=utf-8',
'Cache-Control': 'no-store',
'Access-Control-Allow-Origin': '*'
});
res.end(fs.readFileSync(histPath));
return;
}
}
res.writeHead(404);
res.end('Latest Clash profile not found');
}
return;
}
if (pathname === '/sub/singbox/latest' && req.method === 'GET') {
const filePath = path.join(outDir, 'CatMata-sub.json');
if (fs.existsSync(filePath)) {
res.writeHead(200, {
'Content-Type': 'application/json; charset=utf-8',
'Cache-Control': 'no-store',
'Access-Control-Allow-Origin': '*'
});
res.end(fs.readFileSync(filePath));
} else {
const history = getHistoryList();
if (history.length > 0 && history[0].jsonFile) {
const histPath = path.join(outDir, 'history', history[0].jsonFile);
if (fs.existsSync(histPath)) {
res.writeHead(200, {
'Content-Type': 'application/json; charset=utf-8',
'Cache-Control': 'no-store',
'Access-Control-Allow-Origin': '*'
});
res.end(fs.readFileSync(histPath));
return;
}
}
res.writeHead(404);
res.end('Latest Sing-box profile not found');
}
return;
}
if (pathname === '/login' || pathname === '/login.html') {
serveHtml(res, 'login.html');
return;