Add SFTP Client Connection on Load

This commit is contained in:
MCHost
2025-06-25 03:42:32 -04:00
parent f0cfcbe195
commit e8f5cdd06f
2 changed files with 82 additions and 68 deletions

View File

@ -180,7 +180,7 @@
<button id="stopBtn" class="bg-red-600 hover:bg-red-700 rounded font-medium control-btn">Stop</button> <button id="stopBtn" class="bg-red-600 hover:bg-red-700 rounded font-medium control-btn">Stop</button>
<button id="restartBtn" <button id="restartBtn"
class="bg-yellow-600 hover:bg-yellow-700 rounded font-medium control-btn">Restart</button> class="bg-yellow-600 hover:bg-yellow-700 rounded font-medium control-btn">Restart</button>
<button id="sftpBtn" class="bg-green-600 hover:bg-green-700 px-4 py-2 rounded">SFTP</button> <!-- <button id="sftpBtn" class="bg-green-600 hover:bg-green-700 px-4 py-2 rounded">SFTP</button> -->
</div> </div>
<button id="editPropertiesBtn" <button id="editPropertiesBtn"

View File

@ -15,6 +15,7 @@ document.addEventListener('DOMContentLoaded', () => {
let allProperties = {}; let allProperties = {};
let sftpCredentials = null; let sftpCredentials = null;
let isSftpOnline = false; let isSftpOnline = false;
let hasAttemptedSftpConnect = false;
const filteredSettings = [ const filteredSettings = [
'bug-report-link', 'bug-report-link',
'query.port', 'query.port',
@ -493,10 +494,11 @@ document.addEventListener('DOMContentLoaded', () => {
const editPropertiesBtn = elements.editPropertiesBtn; const editPropertiesBtn = elements.editPropertiesBtn;
const updateModsBtn = elements.updateModsBtn; const updateModsBtn = elements.updateModsBtn;
const backupBtn = elements.backupBtn; const backupBtn = elements.backupBtn;
const sftpBtn = elements.sftpBtn; // const sftpBtn = elements.sftpBtn; // Commented out as it appears to be disabled in the provided code
const startBtn = document.getElementById('startBtn'); const startBtn = document.getElementById('startBtn');
const stopBtn = elements.stopBtn; const stopBtn = elements.stopBtn;
const restartBtn = elements.restartBtn; const restartBtn = elements.restartBtn;
const sftpBrowserSection = elements.sftpBrowserSection;
if (startBtn) { if (startBtn) {
if (status.toLowerCase() === 'running') { if (status.toLowerCase() === 'running') {
@ -523,9 +525,9 @@ document.addEventListener('DOMContentLoaded', () => {
if (backupBtn) { if (backupBtn) {
backupBtn.classList.add('hidden'); backupBtn.classList.add('hidden');
} }
if (sftpBtn) { // if (sftpBtn) {
sftpBtn.classList.add('hidden'); // sftpBtn.classList.add('hidden');
} // }
if (stopBtn) { if (stopBtn) {
stopBtn.disabled = true; stopBtn.disabled = true;
stopBtn.classList.add('disabled-btn'); stopBtn.classList.add('disabled-btn');
@ -534,6 +536,9 @@ document.addEventListener('DOMContentLoaded', () => {
restartBtn.disabled = true; restartBtn.disabled = true;
restartBtn.classList.add('disabled-btn'); restartBtn.classList.add('disabled-btn');
} }
if (sftpBrowserSection) {
sftpBrowserSection.style.display = 'none';
}
if (!state.hasShownStartNotification) { if (!state.hasShownStartNotification) {
showNotification('Server is stopped. Click "Start" to enable all features.', 'error', 'server-stopped'); showNotification('Server is stopped. Click "Start" to enable all features.', 'error', 'server-stopped');
state.hasShownStartNotification = true; state.hasShownStartNotification = true;
@ -551,9 +556,9 @@ document.addEventListener('DOMContentLoaded', () => {
if (backupBtn) { if (backupBtn) {
backupBtn.classList.remove('hidden'); backupBtn.classList.remove('hidden');
} }
if (sftpBtn) { // if (sftpBtn) {
sftpBtn.classList.remove('hidden'); // sftpBtn.classList.remove('hidden');
} // }
if (stopBtn) { if (stopBtn) {
stopBtn.disabled = false; stopBtn.disabled = false;
stopBtn.classList.remove('disabled-btn'); stopBtn.classList.remove('disabled-btn');
@ -562,9 +567,12 @@ document.addEventListener('DOMContentLoaded', () => {
restartBtn.disabled = false; restartBtn.disabled = false;
restartBtn.classList.remove('disabled-btn'); restartBtn.classList.remove('disabled-btn');
} }
if (sftpBrowserSection) {
sftpBrowserSection.style.display = 'block';
}
state.hasShownStartNotification = false; state.hasShownStartNotification = false;
} }
} }
function updateDockerLogsUI(message) { function updateDockerLogsUI(message) {
if (message.error) { if (message.error) {
@ -621,13 +629,14 @@ document.addEventListener('DOMContentLoaded', () => {
} }
} }
function updateSftpCacheUI(message) { function updateSftpCacheUI(message) {
if (message.data?.hostname && message.data?.port && message.data?.user && message.data?.password) {
// For testing, this is currently configured to be internally networked to port 22 for the given container. // For testing, this is currently configured to be internally networked to port 22 for the given container.
// The IP Address is sent from server side on page load, in theory, this should allow us to always allow // The IP Address is sent from server side on page load, in theory, this should allow us to always allow
// SFTP Client to WORK! Even if SFTP Holesail ports are down! // SFTP Client to WORK! Even if SFTP Holesail ports are down!
// To Revert, move hostname to message.data.hostname and port to message.data.port // To Revert, move hostname to message.data.hostname and port to message.data.port
// Doing so will configure the connection to the Jump node. // Doing so will configure the connection to the Jump node.
if (message.data?.hostname && message.data?.port && message.data?.user && message.data?.password) {
sftpCredentials = { sftpCredentials = {
hostname: message.data.ipAddress, hostname: message.data.ipAddress,
port: 22, port: 22,
@ -639,6 +648,11 @@ document.addEventListener('DOMContentLoaded', () => {
elements.sftpLink.textContent = sftpLinkText; elements.sftpLink.textContent = sftpLinkText;
state.sftpLink = sftpLinkText; state.sftpLink = sftpLinkText;
} }
// Call connectSftp only if it hasn't been attempted yet
if (!hasAttemptedSftpConnect) {
hasAttemptedSftpConnect = true;
connectSftp();
}
} }
} }
@ -1655,7 +1669,7 @@ document.addEventListener('DOMContentLoaded', () => {
} }
}); });
elements.sftpBtn.addEventListener('click', connectSftp); // elements.sftpBtn.addEventListener('click', connectSftp);
document.getElementById('refresh').addEventListener('click', async () => { document.getElementById('refresh').addEventListener('click', async () => {
if (ws && ws.readyState === WebSocket.OPEN) { if (ws && ws.readyState === WebSocket.OPEN) {