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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user