fix: start button producing 404s. Fix checks docker status
This commit is contained in:
@ -189,7 +189,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
function initializeCharts() {
|
function initializeCharts() {
|
||||||
if (memoryMeter || cpuMeter) {
|
if (memoryMeter || cpuMeter) {
|
||||||
//console.log('Charts already initialized, skipping');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +238,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
type: 'doughnut',
|
type: 'doughnut',
|
||||||
data: {
|
data: {
|
||||||
datasets: [{
|
datasets: [{
|
||||||
data: [0, 600], // Initialize with max 600 for 6 cores
|
data: [0, 600],
|
||||||
backgroundColor: ['#3B82F6', '#4B5563'],
|
backgroundColor: ['#3B82F6', '#4B5563'],
|
||||||
borderWidth: 0,
|
borderWidth: 0,
|
||||||
circumference: 180,
|
circumference: 180,
|
||||||
@ -286,14 +285,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
function connectWebSocket() {
|
function connectWebSocket() {
|
||||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
//console.log('WebSocket already connected, skipping');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ws = new WebSocket(`wss://${window.location.host}/ws?apiKey=${encodeURIComponent(apiKey)}`);
|
ws = new WebSocket(`wss://${window.location.host}/ws?apiKey=${encodeURIComponent(apiKey)}`);
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
//console.log('WebSocket connected');
|
|
||||||
showMainContent();
|
showMainContent();
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
type: 'subscribe',
|
type: 'subscribe',
|
||||||
@ -309,7 +306,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
try {
|
try {
|
||||||
clearTimeout(responseTimeout);
|
clearTimeout(responseTimeout);
|
||||||
const message = JSON.parse(event.data);
|
const message = JSON.parse(event.data);
|
||||||
//console.log('WebSocket message received:', message);
|
|
||||||
if (message.requestId && pendingRequests.has(message.requestId)) {
|
if (message.requestId && pendingRequests.has(message.requestId)) {
|
||||||
const { resolve, reject, notification } = pendingRequests.get(message.requestId);
|
const { resolve, reject, notification } = pendingRequests.get(message.requestId);
|
||||||
pendingRequests.delete(message.requestId);
|
pendingRequests.delete(message.requestId);
|
||||||
@ -336,7 +332,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = () => {
|
ws.onclose = () => {
|
||||||
//console.log('WebSocket disconnected');
|
|
||||||
showLoginPage();
|
showLoginPage();
|
||||||
clearTimeout(responseTimeout);
|
clearTimeout(responseTimeout);
|
||||||
if (terminal) {
|
if (terminal) {
|
||||||
@ -382,7 +377,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateDockerUI(message) {
|
function updateDockerUI(message) {
|
||||||
//console.log('Updating Docker UI:', message);
|
|
||||||
if (message.error) {
|
if (message.error) {
|
||||||
if (elements.serverStatus) elements.serverStatus.textContent = 'Not Running';
|
if (elements.serverStatus) elements.serverStatus.textContent = 'Not Running';
|
||||||
toggleSections('error');
|
toggleSections('error');
|
||||||
@ -391,7 +385,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
const memoryPercent = parseFloat(message.data?.memory?.percent) || 0;
|
const memoryPercent = parseFloat(message.data?.memory?.percent) || 0;
|
||||||
if (state.memoryPercent !== memoryPercent && elements.memoryPercent && memoryMeter) {
|
if (state.memoryPercent !== memoryPercent && elements.memoryPercent && memoryMeter) {
|
||||||
//console.log(`Updating memory meter: ${memoryPercent}%`);
|
|
||||||
memoryMeter.data.datasets[0].data = [memoryPercent, 100 - memoryPercent];
|
memoryMeter.data.datasets[0].data = [memoryPercent, 100 - memoryPercent];
|
||||||
memoryMeter.update();
|
memoryMeter.update();
|
||||||
elements.memoryPercent.textContent = `${memoryPercent.toFixed(1)}%`;
|
elements.memoryPercent.textContent = `${memoryPercent.toFixed(1)}%`;
|
||||||
@ -400,19 +393,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
const cpuPercent = parseFloat(message.data?.cpu) || 0;
|
const cpuPercent = parseFloat(message.data?.cpu) || 0;
|
||||||
if (state.cpuPercent !== cpuPercent && elements.cpuPercent && cpuMeter) {
|
if (state.cpuPercent !== cpuPercent && elements.cpuPercent && cpuMeter) {
|
||||||
//console.log(`Updating CPU meter: ${cpuPercent}%`);
|
|
||||||
// Scale CPU percent to 0-100 for the chart (600% max becomes 100% on chart)
|
|
||||||
const scaledCpuPercent = Math.min((cpuPercent / 600) * 100, 100);
|
const scaledCpuPercent = Math.min((cpuPercent / 600) * 100, 100);
|
||||||
cpuMeter.data.datasets[0].data = [scaledCpuPercent, 100 - scaledCpuPercent];
|
cpuMeter.data.datasets[0].data = [scaledCpuPercent, 100 - scaledCpuPercent];
|
||||||
cpuMeter.update();
|
cpuMeter.update();
|
||||||
// Display actual CPU percent (up to 600%)
|
|
||||||
elements.cpuPercent.textContent = `${cpuPercent.toFixed(1)}%`;
|
elements.cpuPercent.textContent = `${cpuPercent.toFixed(1)}%`;
|
||||||
state.cpuPercent = cpuPercent;
|
state.cpuPercent = cpuPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = message.data?.status || 'Unknown';
|
const status = message.data?.status || 'Unknown';
|
||||||
if (state.serverStatus !== status && elements.serverStatus) {
|
if (state.serverStatus !== status && elements.serverStatus) {
|
||||||
//console.log(`Updating status: ${status}`);
|
|
||||||
elements.serverStatus.textContent = status;
|
elements.serverStatus.textContent = status;
|
||||||
state.serverStatus = status;
|
state.serverStatus = status;
|
||||||
toggleSections(status);
|
toggleSections(status);
|
||||||
@ -478,7 +467,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateDockerLogsUI(message) {
|
function updateDockerLogsUI(message) {
|
||||||
//console.log('Updating Docker Logs UI:', message);
|
|
||||||
if (message.error) {
|
if (message.error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -503,7 +491,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateConnectionStatusUI(message) {
|
function updateConnectionStatusUI(message) {
|
||||||
//console.log('Updating Connection Status UI:', message);
|
|
||||||
if (message.data?.isOnline !== undefined && elements.connectionStatus) {
|
if (message.data?.isOnline !== undefined && elements.connectionStatus) {
|
||||||
const statusIcon = message.data.isOnline ? '✅' : '❌';
|
const statusIcon = message.data.isOnline ? '✅' : '❌';
|
||||||
if (state.connectionStatus !== statusIcon) {
|
if (state.connectionStatus !== statusIcon) {
|
||||||
@ -514,7 +501,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateGeyserStatusUI(message) {
|
function updateGeyserStatusUI(message) {
|
||||||
//console.log('Updating Geyser Status UI:', message);
|
|
||||||
if (message.data?.isOnline !== undefined && elements.geyserStatus) {
|
if (message.data?.isOnline !== undefined && elements.geyserStatus) {
|
||||||
const statusIcon = message.data.isOnline ? '✅' : '❌';
|
const statusIcon = message.data.isOnline ? '✅' : '❌';
|
||||||
if (state.geyserStatus !== statusIcon) {
|
if (state.geyserStatus !== statusIcon) {
|
||||||
@ -525,7 +511,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateSftpStatusUI(message) {
|
function updateSftpStatusUI(message) {
|
||||||
//console.log('Updating SFTP Status UI:', message);
|
|
||||||
if (message.data?.isOnline !== undefined && elements.sftpStatus) {
|
if (message.data?.isOnline !== undefined && elements.sftpStatus) {
|
||||||
const statusIcon = message.data.isOnline ? '✅' : '❌';
|
const statusIcon = message.data.isOnline ? '✅' : '❌';
|
||||||
if (state.sftpStatus !== statusIcon) {
|
if (state.sftpStatus !== statusIcon) {
|
||||||
@ -536,7 +521,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateNonDockerUI(message) {
|
function updateNonDockerUI(message) {
|
||||||
//console.log('Updating Non-Docker UI:', message);
|
|
||||||
if (message.error) {
|
if (message.error) {
|
||||||
if (message.error.includes('Missing token') || message.error.includes('HTTP 403')) {
|
if (message.error.includes('Missing token') || message.error.includes('HTTP 403')) {
|
||||||
showNotification('Invalid or missing API key. Please log in again.', 'error');
|
showNotification('Invalid or missing API key. Please log in again.', 'error');
|
||||||
@ -550,7 +534,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (message.type === 'hello' && message.data?.message) {
|
if (message.type === 'hello' && message.data?.message) {
|
||||||
const user = message.data.message.split(', ')[1]?.replace('!', '').trim() || 'Unknown';
|
const user = message.data.message.split(', ')[1]?.replace('!', '').trim() || 'Unknown';
|
||||||
if (state.user !== user && elements.user) {
|
if (state.user !== user && elements.user) {
|
||||||
//console.log(`Updating user: ${user}`);
|
|
||||||
elements.user.textContent = user;
|
elements.user.textContent = user;
|
||||||
state.user = user;
|
state.user = user;
|
||||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
@ -561,7 +544,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
if (message.type === 'time' && message.data?.keyexpireString) {
|
if (message.type === 'time' && message.data?.keyexpireString) {
|
||||||
if (state.keyExpiry !== message.data.keyexpireString && elements.keyExpiry) {
|
if (state.keyExpiry !== message.data.keyexpireString && elements.keyExpiry) {
|
||||||
//console.log(`Updating key expiry: ${message.data.keyexpireString}`);
|
|
||||||
const expiryDate = new Date(message.data.keyexpireString);
|
const expiryDate = new Date(message.data.keyexpireString);
|
||||||
const formattedDate = expiryDate.toLocaleString('en-US', {
|
const formattedDate = expiryDate.toLocaleString('en-US', {
|
||||||
month: 'long',
|
month: 'long',
|
||||||
@ -595,7 +577,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
`).join('')
|
`).join('')
|
||||||
: 'None';
|
: 'None';
|
||||||
if (state.playerList !== playerListHtml && elements.playerList) {
|
if (state.playerList !== playerListHtml && elements.playerList) {
|
||||||
//console.log(`Updating player list: ${playerListHtml}`);
|
|
||||||
elements.playerList.innerHTML = playerListHtml;
|
elements.playerList.innerHTML = playerListHtml;
|
||||||
state.playerList = playerListHtml;
|
state.playerList = playerListHtml;
|
||||||
document.querySelectorAll('.kick-player').forEach(button => {
|
document.querySelectorAll('.kick-player').forEach(button => {
|
||||||
@ -757,7 +738,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
if (state.modListHtml !== modListHtml && elements.modList) {
|
if (state.modListHtml !== modListHtml && elements.modList) {
|
||||||
//console.log('Updating mod list');
|
|
||||||
elements.modList.innerHTML = modListHtml;
|
elements.modList.innerHTML = modListHtml;
|
||||||
state.modListHtml = modListHtml;
|
state.modListHtml = modListHtml;
|
||||||
document.querySelectorAll('.uninstall-mod').forEach(button => {
|
document.querySelectorAll('.uninstall-mod').forEach(button => {
|
||||||
@ -777,7 +757,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
if (message.type === 'log' && message.data?.message) {
|
if (message.type === 'log' && message.data?.message) {
|
||||||
if (state.logUrl !== message.data.message && elements.logUrl) {
|
if (state.logUrl !== message.data.message && elements.logUrl) {
|
||||||
//console.log(`Updating log URL: ${message.data.message}`);
|
|
||||||
elements.logUrl.href = message.data.message;
|
elements.logUrl.href = message.data.message;
|
||||||
elements.logUrl.textContent = message.data.message;
|
elements.logUrl.textContent = message.data.message;
|
||||||
state.logUrl = message.data.message;
|
state.logUrl = message.data.message;
|
||||||
@ -786,7 +765,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
if (message.type === 'website' && message.data?.message) {
|
if (message.type === 'website' && message.data?.message) {
|
||||||
if (state.websiteUrl !== message.data.message && elements.websiteUrl) {
|
if (state.websiteUrl !== message.data.message && elements.websiteUrl) {
|
||||||
//console.log(`Updating website URL: ${message.data.message}`);
|
|
||||||
elements.websiteUrl.href = message.data.message;
|
elements.websiteUrl.href = message.data.message;
|
||||||
elements.websiteUrl.textContent = message.data.message;
|
elements.websiteUrl.textContent = message.data.message;
|
||||||
state.websiteUrl = message.data.message;
|
state.websiteUrl = message.data.message;
|
||||||
@ -795,7 +773,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
if (message.type === 'map' && message.data?.message) {
|
if (message.type === 'map' && message.data?.message) {
|
||||||
if (state.mapUrl !== message.data.message && elements.mapUrl) {
|
if (state.mapUrl !== message.data.message && elements.mapUrl) {
|
||||||
//console.log(`Updating map URL: ${message.data.message}`);
|
|
||||||
elements.mapUrl.href = message.data.message;
|
elements.mapUrl.href = message.data.message;
|
||||||
elements.mapUrl.textContent = message.data.message;
|
elements.mapUrl.textContent = message.data.message;
|
||||||
state.mapUrl = message.data.message;
|
state.mapUrl = message.data.message;
|
||||||
@ -805,7 +782,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (message.type === 'my-link-cache' && message.data?.hostname && message.data?.port) {
|
if (message.type === 'my-link-cache' && message.data?.hostname && message.data?.port) {
|
||||||
const myLinkText = `${message.data.hostname}:${message.data.port}`;
|
const myLinkText = `${message.data.hostname}:${message.data.port}`;
|
||||||
if (state.myLink !== myLinkText && elements.myLink) {
|
if (state.myLink !== myLinkText && elements.myLink) {
|
||||||
//console.log(`Updating my link: ${myLinkText}`);
|
|
||||||
elements.myLink.textContent = myLinkText;
|
elements.myLink.textContent = myLinkText;
|
||||||
state.myLink = myLinkText;
|
state.myLink = myLinkText;
|
||||||
}
|
}
|
||||||
@ -814,7 +790,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (message.type === 'my-geyser-cache' && message.data?.hostname && message.data?.port) {
|
if (message.type === 'my-geyser-cache' && message.data?.hostname && message.data?.port) {
|
||||||
const geyserLinkText = `${message.data.hostname}:${message.data.port}`;
|
const geyserLinkText = `${message.data.hostname}:${message.data.port}`;
|
||||||
if (state.geyserLink !== geyserLinkText && elements.geyserLink) {
|
if (state.geyserLink !== geyserLinkText && elements.geyserLink) {
|
||||||
//console.log(`Updating geyser link: ${geyserLinkText}`);
|
|
||||||
elements.geyserLink.textContent = geyserLinkText;
|
elements.geyserLink.textContent = geyserLinkText;
|
||||||
state.geyserLink = geyserLinkText;
|
state.geyserLink = geyserLinkText;
|
||||||
}
|
}
|
||||||
@ -823,7 +798,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (message.type === 'my-sftp-cache' && message.data?.hostname && message.data?.port && message.data?.user && message.data?.password) {
|
if (message.type === 'my-sftp-cache' && message.data?.hostname && message.data?.port && message.data?.user && message.data?.password) {
|
||||||
const sftpLinkText = `${message.data.hostname}:${message.data.port} (Auth: User: ${message.data.user} | Pass: ${message.data.password})`;
|
const sftpLinkText = `${message.data.hostname}:${message.data.port} (Auth: User: ${message.data.user} | Pass: ${message.data.password})`;
|
||||||
if (state.sftpLink !== sftpLinkText && elements.sftpLink) {
|
if (state.sftpLink !== sftpLinkText && elements.sftpLink) {
|
||||||
//console.log(`Updating SFTP link: ${sftpLinkText}`);
|
|
||||||
elements.sftpLink.textContent = sftpLinkText;
|
elements.sftpLink.textContent = sftpLinkText;
|
||||||
state.sftpLink = sftpLinkText;
|
state.sftpLink = sftpLinkText;
|
||||||
}
|
}
|
||||||
@ -832,7 +806,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (message.type === 'my-link' && message.data?.hostname && message.data?.port) {
|
if (message.type === 'my-link' && message.data?.hostname && message.data?.port) {
|
||||||
const myLinkText = `${message.data.hostname}:${message.data.port}`;
|
const myLinkText = `${message.data.hostname}:${message.data.port}`;
|
||||||
if (state.myLink !== myLinkText && elements.myLink) {
|
if (state.myLink !== myLinkText && elements.myLink) {
|
||||||
//console.log(`Updating my link from generate: ${myLinkText}`);
|
|
||||||
elements.myLink.textContent = myLinkText;
|
elements.myLink.textContent = myLinkText;
|
||||||
state.myLink = myLinkText;
|
state.myLink = myLinkText;
|
||||||
}
|
}
|
||||||
@ -841,7 +814,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (message.type === 'my-geyser-link' && message.data?.hostname && message.data?.port) {
|
if (message.type === 'my-geyser-link' && message.data?.hostname && message.data?.port) {
|
||||||
const geyserLinkText = `${message.data.hostname}:${message.data.port}`;
|
const geyserLinkText = `${message.data.hostname}:${message.data.port}`;
|
||||||
if (state.geyserLink !== geyserLinkText && elements.geyserLink) {
|
if (state.geyserLink !== geyserLinkText && elements.geyserLink) {
|
||||||
//console.log(`Updating geyser link from generate: ${geyserLinkText}`);
|
|
||||||
elements.geyserLink.textContent = geyserLinkText;
|
elements.geyserLink.textContent = geyserLinkText;
|
||||||
state.geyserLink = geyserLinkText;
|
state.geyserLink = geyserLinkText;
|
||||||
}
|
}
|
||||||
@ -850,7 +822,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (message.type === 'my-sftp' && message.data?.hostname && message.data?.port && message.data?.user) {
|
if (message.type === 'my-sftp' && message.data?.hostname && message.data?.port && message.data?.user) {
|
||||||
const sftpLinkText = `${message.data.hostname}:${message.data.port} (User: ${message.data.user})`;
|
const sftpLinkText = `${message.data.hostname}:${message.data.port} (User: ${message.data.user})`;
|
||||||
if (state.sftpLink !== sftpLinkText && elements.sftpLink) {
|
if (state.sftpLink !== sftpLinkText && elements.sftpLink) {
|
||||||
//console.log(`Updating SFTP link from generate: ${sftpLinkText}`);
|
|
||||||
elements.sftpLink.textContent = sftpLinkText;
|
elements.sftpLink.textContent = sftpLinkText;
|
||||||
state.sftpLink = sftpLinkText;
|
state.sftpLink = sftpLinkText;
|
||||||
}
|
}
|
||||||
@ -926,7 +897,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updatePagination() {
|
function updatePagination() {
|
||||||
//console.log(`Updating pagination: totalResults=${totalResults}, currentPage=${currentPage}`);
|
|
||||||
const totalPages = Math.max(1, Math.ceil(totalResults / resultsPerPage));
|
const totalPages = Math.max(1, Math.ceil(totalResults / resultsPerPage));
|
||||||
elements.pagination.innerHTML = '';
|
elements.pagination.innerHTML = '';
|
||||||
|
|
||||||
@ -939,7 +909,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}`;
|
}`;
|
||||||
if (!disabled && page !== currentPage) {
|
if (!disabled && page !== currentPage) {
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
//console.log(`Navigating to page ${page}`);
|
|
||||||
currentPage = page;
|
currentPage = page;
|
||||||
searchMods();
|
searchMods();
|
||||||
});
|
});
|
||||||
@ -957,11 +926,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
createPageButton(currentPage + 1, 'Next', currentPage === totalPages);
|
createPageButton(currentPage + 1, 'Next', currentPage === totalPages);
|
||||||
}
|
}
|
||||||
//console.log(`Pagination updated: ${totalPages} pages`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeSearch() {
|
function closeSearch() {
|
||||||
//console.log('Closing search results');
|
|
||||||
elements.modSearch.value = '';
|
elements.modSearch.value = '';
|
||||||
elements.modResults.innerHTML = '';
|
elements.modResults.innerHTML = '';
|
||||||
elements.pagination.innerHTML = '';
|
elements.pagination.innerHTML = '';
|
||||||
@ -976,12 +943,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (mod) {
|
if (mod) {
|
||||||
try {
|
try {
|
||||||
const offset = (currentPage - 1) * resultsPerPage;
|
const offset = (currentPage - 1) * resultsPerPage;
|
||||||
//console.log(`Searching mods: mod=${mod}, offset=${offset}, page=${currentPage}`);
|
|
||||||
const response = await wsRequest('/search', 'POST', { mod, offset });
|
const response = await wsRequest('/search', 'POST', { mod, offset });
|
||||||
//console.log('Search response:', response);
|
|
||||||
if (elements.modResults) {
|
if (elements.modResults) {
|
||||||
totalResults = response.totalHits || response.results?.length || 0;
|
totalResults = response.totalHits || response.results?.length || 0;
|
||||||
//console.log(`Total results set to: ${totalResults}`);
|
|
||||||
elements.modResults.innerHTML = response.results?.length > 0 ? response.results.map(result => `
|
elements.modResults.innerHTML = response.results?.length > 0 ? response.results.map(result => `
|
||||||
<div class="bg-gray-700 p-4 rounded">
|
<div class="bg-gray-700 p-4 rounded">
|
||||||
<p><strong>${result.title}</strong></p>
|
<p><strong>${result.title}</strong></p>
|
||||||
@ -1306,39 +1270,32 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
initializeTerminal();
|
initializeTerminal();
|
||||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
ws.send(JSON.stringify({ type: 'subscribe', endpoints: ['docker', 'docker-logs'] }));
|
ws.send(JSON.stringify({ type: 'subscribe', endpoints: ['docker', 'docker-logs'] }));
|
||||||
|
// Set up a one-time message listener for the docker status
|
||||||
|
const messageHandler = (event) => {
|
||||||
|
try {
|
||||||
|
const message = JSON.parse(event.data);
|
||||||
|
if (message.type === 'docker' && message.data?.status === 'running') {
|
||||||
|
updateNotification(notification, 'Server started successfully', 'success');
|
||||||
|
toggleSections('running');
|
||||||
|
ws.removeEventListener('message', messageHandler); // Remove listener after success
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error parsing WebSocket message:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.addEventListener('message', messageHandler);
|
||||||
|
// Timeout to handle case where running status isn't received
|
||||||
|
setTimeout(() => {
|
||||||
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
|
ws.removeEventListener('message', messageHandler);
|
||||||
|
if (state.serverStatus !== 'running') {
|
||||||
|
updateNotification(notification, 'Server failed to start', 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 30000); // 30 seconds timeout
|
||||||
} else {
|
} else {
|
||||||
console.warn('WebSocket not connected, cannot subscribe to docker events');
|
|
||||||
updateNotification(notification, 'WebSocket not connected', 'error');
|
updateNotification(notification, 'WebSocket not connected', 'error');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Poll server status until it becomes 'Running' or timeout
|
|
||||||
let attempts = 0;
|
|
||||||
const maxAttempts = 30; // 30 seconds (1 second per attempt)
|
|
||||||
const checkStatus = async () => {
|
|
||||||
try {
|
|
||||||
const response = await wsRequest('/status', 'GET');
|
|
||||||
const status = response?.data?.status || 'Unknown';
|
|
||||||
if (status.toLowerCase() === 'running') {
|
|
||||||
updateNotification(notification, 'Server started successfully', 'success');
|
|
||||||
state.serverStatus = status;
|
|
||||||
elements.serverStatus.textContent = status;
|
|
||||||
toggleSections(status);
|
|
||||||
} else if (attempts < maxAttempts) {
|
|
||||||
attempts++;
|
|
||||||
setTimeout(checkStatus, 1000);
|
|
||||||
} else {
|
|
||||||
updateNotification(notification, 'Server start timed out', 'error');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (attempts < maxAttempts) {
|
|
||||||
attempts++;
|
|
||||||
setTimeout(checkStatus, 1000);
|
|
||||||
} else {
|
|
||||||
updateNotification(notification, `Failed to verify server status: ${error.message}`, 'error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
setTimeout(checkStatus, 1000);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Start server error:', error);
|
console.error('Start server error:', error);
|
||||||
showNotification(`Failed to start server: ${error.message}`, 'error');
|
showNotification(`Failed to start server: ${error.message}`, 'error');
|
||||||
|
Reference in New Issue
Block a user