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="restartBtn"
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>
<button id="editPropertiesBtn"

View File

@ -15,6 +15,7 @@ document.addEventListener('DOMContentLoaded', () => {
let allProperties = {};
let sftpCredentials = null;
let isSftpOnline = false;
let hasAttemptedSftpConnect = false;
const filteredSettings = [
'bug-report-link',
'query.port',
@ -493,10 +494,11 @@ document.addEventListener('DOMContentLoaded', () => {
const editPropertiesBtn = elements.editPropertiesBtn;
const updateModsBtn = elements.updateModsBtn;
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 stopBtn = elements.stopBtn;
const restartBtn = elements.restartBtn;
const sftpBrowserSection = elements.sftpBrowserSection;
if (startBtn) {
if (status.toLowerCase() === 'running') {
@ -523,9 +525,9 @@ document.addEventListener('DOMContentLoaded', () => {
if (backupBtn) {
backupBtn.classList.add('hidden');
}
if (sftpBtn) {
sftpBtn.classList.add('hidden');
}
// if (sftpBtn) {
// sftpBtn.classList.add('hidden');
// }
if (stopBtn) {
stopBtn.disabled = true;
stopBtn.classList.add('disabled-btn');
@ -534,6 +536,9 @@ document.addEventListener('DOMContentLoaded', () => {
restartBtn.disabled = true;
restartBtn.classList.add('disabled-btn');
}
if (sftpBrowserSection) {
sftpBrowserSection.style.display = 'none';
}
if (!state.hasShownStartNotification) {
showNotification('Server is stopped. Click "Start" to enable all features.', 'error', 'server-stopped');
state.hasShownStartNotification = true;
@ -551,9 +556,9 @@ document.addEventListener('DOMContentLoaded', () => {
if (backupBtn) {
backupBtn.classList.remove('hidden');
}
if (sftpBtn) {
sftpBtn.classList.remove('hidden');
}
// if (sftpBtn) {
// sftpBtn.classList.remove('hidden');
// }
if (stopBtn) {
stopBtn.disabled = false;
stopBtn.classList.remove('disabled-btn');
@ -562,6 +567,9 @@ document.addEventListener('DOMContentLoaded', () => {
restartBtn.disabled = false;
restartBtn.classList.remove('disabled-btn');
}
if (sftpBrowserSection) {
sftpBrowserSection.style.display = 'block';
}
state.hasShownStartNotification = false;
}
}
@ -621,13 +629,14 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
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.
// 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!
// To Revert, move hostname to message.data.hostname and port to message.data.port
// Doing so will configure the connection to the Jump node.
if (message.data?.hostname && message.data?.port && message.data?.user && message.data?.password) {
sftpCredentials = {
hostname: message.data.ipAddress,
port: 22,
@ -639,6 +648,11 @@ document.addEventListener('DOMContentLoaded', () => {
elements.sftpLink.textContent = 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 () => {
if (ws && ws.readyState === WebSocket.OPEN) {