mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-09-19 09:40:14 +00:00
feat: enhance server handling and add empty state messaging in Server component
This commit is contained in:
@@ -114,11 +114,16 @@ function updateServerMetrics() {
|
||||
}
|
||||
|
||||
function websocketPayload() {
|
||||
return JSON.stringify({
|
||||
now: Date.now(),
|
||||
online: onlineCount,
|
||||
servers,
|
||||
});
|
||||
const payload = { now: Date.now() };
|
||||
|
||||
if (onlineCount > 0) {
|
||||
payload.online = onlineCount;
|
||||
}
|
||||
if (servers.length > 0) {
|
||||
payload.servers = servers;
|
||||
}
|
||||
|
||||
return JSON.stringify(payload);
|
||||
}
|
||||
|
||||
function jsonResponse(response, data) {
|
||||
@@ -130,7 +135,7 @@ function jsonResponse(response, data) {
|
||||
response.end(JSON.stringify(data));
|
||||
}
|
||||
|
||||
const serverGroups = [
|
||||
const populatedServerGroups = [
|
||||
{
|
||||
group: {
|
||||
id: 1,
|
||||
@@ -166,6 +171,7 @@ const serverGroups = [
|
||||
.map((server) => server.id),
|
||||
},
|
||||
];
|
||||
const serverGroups = serverCount === 0 ? [] : populatedServerGroups;
|
||||
|
||||
const serviceHistory = Array.from({ length: 30 }, (_, index) => ({
|
||||
up: 95 + (index % 6),
|
||||
@@ -173,6 +179,22 @@ const serviceHistory = Array.from({ length: 30 }, (_, index) => ({
|
||||
delay: 20 + index * 3,
|
||||
}));
|
||||
|
||||
const services =
|
||||
serverCount === 0
|
||||
? {}
|
||||
: {
|
||||
mock_http: {
|
||||
service_name: "Mock HTTP",
|
||||
current_up: 1,
|
||||
current_down: 0,
|
||||
total_up: 2999,
|
||||
total_down: 1,
|
||||
delay: serviceHistory.map((item) => item.delay),
|
||||
up: serviceHistory.map((item) => item.up),
|
||||
down: serviceHistory.map((item) => item.down),
|
||||
},
|
||||
};
|
||||
|
||||
const httpServer = http.createServer((request, response) => {
|
||||
const requestUrl = new URL(
|
||||
request.url || "/",
|
||||
@@ -213,18 +235,7 @@ const httpServer = http.createServer((request, response) => {
|
||||
jsonResponse(response, {
|
||||
success: true,
|
||||
data: {
|
||||
services: {
|
||||
mock_http: {
|
||||
service_name: "Mock HTTP",
|
||||
current_up: 1,
|
||||
current_down: 0,
|
||||
total_up: 2999,
|
||||
total_down: 1,
|
||||
delay: serviceHistory.map((item) => item.delay),
|
||||
up: serviceHistory.map((item) => item.up),
|
||||
down: serviceHistory.map((item) => item.down),
|
||||
},
|
||||
},
|
||||
services,
|
||||
cycle_transfer_stats: {},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user