diff --git a/includes/websocket.js b/includes/websocket.js index ead7d56..be2d7cb 100644 --- a/includes/websocket.js +++ b/includes/websocket.js @@ -4,7 +4,7 @@ import { checkConnectionStatus, checkGeyserStatus, checkSftpStatus } from './sta import { apiRequest } from './api.js'; const clients = new Map(); -const staticEndpoints = ['log', 'website', 'map', 'my-link-cache', 'my-geyser-cache', 'my-sftp-cache', 'my-link', 'my-geyser-link', 'my-sftp']; +const staticEndpoints = ['log', 'website', 'map', 'my-link-cache', 'my-geyser-cache', 'my-sftp-cache', 'my-link', 'my-geyser-link', 'my-sftp', 'holesail-hashes']; const dynamicEndpoints = ['hello', 'time', 'mod-list']; // Helper function to start Docker stats interval @@ -94,6 +94,44 @@ async function fetchAndSendUpdate(ws, endpoint, client, docker) { return; } + if (endpoint === 'holesail-hashes' && client.cache['holesail-hashes']) { + ws.send(JSON.stringify({ type: endpoint, data: client.cache['holesail-hashes'] })); + return; + } + + if (endpoint === 'holesail-hashes') { + try { + const [hashResponse, geyserHashResponse, sftpHashResponse] = await Promise.all([ + apiRequest('/my-hash', client.apiKey), + apiRequest('/my-geyser-hash', client.apiKey), + apiRequest('/my-sftp-hash', client.apiKey) + ]); + + const response = { + myHash: hashResponse.success ? hashResponse.message : null, + geyserHash: geyserHashResponse.success ? geyserHashResponse.message : null, + sftpHash: sftpHashResponse.success ? sftpHashResponse.message : null, + errors: [] + }; + + if (!hashResponse.success) response.errors.push(`my-hash: ${hashResponse.message || 'Failed to fetch'}`); + if (!geyserHashResponse.success) response.errors.push(`my-geyser-hash: ${geyserHashResponse.message || 'Failed to fetch'}`); + if (!sftpHashResponse.success) response.errors.push(`my-sftp-hash: ${sftpHashResponse.message || 'Failed to fetch'}`); + + client.cache['holesail-hashes'] = response; + + if (ws.readyState === ws.OPEN) { + ws.send(JSON.stringify({ type: endpoint, data: response })); + } + } catch (error) { + console.error(`Error fetching holesail-hashes for ${client.user}:`, error.message); + if (ws.readyState === ws.OPEN) { + ws.send(JSON.stringify({ type: endpoint, error: `Failed to fetch holesail hashes: ${error.message}` })); + } + } + return; + } + const response = await apiRequest(`/${endpoint}`, client.apiKey); if (!response.error) { if (endpoint === 'time') client.cache['time'] = response; @@ -174,7 +212,6 @@ async function fetchAndSendUpdate(ws, endpoint, client, docker) { } } - async function manageStatusChecks(ws, client, user, docker) { try { const container = docker.getContainer(user); @@ -402,7 +439,7 @@ export function handleWebSocket(ws, req, docker) { client.intervals.push(setInterval(async () => { try { for (const endpoint of staticEndpoints) { - if (client.subscriptions.has(endpoint)) { + if (client.subscriptions.has(endpoint) && endpoint !== 'holesail-hashes') { await fetchAndSendUpdate(ws, endpoint, client, docker); } } diff --git a/public/index.html b/public/index.html index 1526607..ba1843c 100644 --- a/public/index.html +++ b/public/index.html @@ -185,7 +185,6 @@ - - @@ -287,6 +284,188 @@ + +
+
+

Holesail Keys

+ +
+
+
+
+

Minecraft Key:

+

Not Loaded

+

Port: 127.0.0.1:25565

+
+ +
+
+
+

Geyser Key:

+

Not Loaded

+

Port: 127.0.0.1:19132

+
+ +
+
+
+

SFTP Key:

+

Not Loaded

+

Port: 127.0.0.1:22

+
+ +
+
+ + + + +
+