Feat: Adding backup button for easy access to download a full server backup
This commit is contained in:
@ -78,7 +78,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
restartBtn: document.getElementById('restartBtn'),
|
||||
connectionStatus: document.getElementById('connectionStatus'),
|
||||
geyserStatus: document.getElementById('geyserStatus'),
|
||||
sftpStatus: document.getElementById('sftpStatus')
|
||||
sftpStatus: document.getElementById('sftpStatus'),
|
||||
backupBtn: document.getElementById('backupBtn')
|
||||
};
|
||||
|
||||
const loadouts = {
|
||||
@ -298,7 +299,21 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
showMainContent();
|
||||
ws.send(JSON.stringify({
|
||||
type: 'subscribe',
|
||||
endpoints: ['docker', 'docker-logs', 'hello', 'time', 'list-players', 'mod-list', 'log', 'website', 'map', 'my-link-cache', 'my-geyser-cache', 'my-sftp-cache']
|
||||
endpoints: [
|
||||
'docker',
|
||||
'docker-logs',
|
||||
'hello',
|
||||
'time',
|
||||
'list-players',
|
||||
'mod-list',
|
||||
'log',
|
||||
'website',
|
||||
'map',
|
||||
'my-link-cache',
|
||||
'my-geyser-cache',
|
||||
'my-sftp-cache',
|
||||
'backup'
|
||||
]
|
||||
}));
|
||||
responseTimeout = setTimeout(() => {
|
||||
showNotification('No response from server. Please check connection or API key.', 'error');
|
||||
@ -377,6 +392,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
updateSftpStatusUI(message);
|
||||
} else if (message.type === 'update-mods') {
|
||||
updateModsUI(message);
|
||||
} else if (message.type === 'backup') {
|
||||
// Backup messages are primarily handled via wsRequest responses
|
||||
console.log('Received backup message:', message);
|
||||
} else {
|
||||
updateNonDockerUI(message);
|
||||
}
|
||||
@ -419,6 +437,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const serverStatusSection = document.querySelector('.bg-gray-800.p-6.rounded-lg.shadow-lg.mb-6[data-section="server-status"]');
|
||||
const editPropertiesBtn = elements.editPropertiesBtn;
|
||||
const updateModsBtn = elements.updateModsBtn;
|
||||
const backupBtn = elements.backupBtn;
|
||||
const startBtn = document.getElementById('startBtn');
|
||||
const stopBtn = elements.stopBtn;
|
||||
const restartBtn = elements.restartBtn;
|
||||
@ -445,6 +464,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (updateModsBtn) {
|
||||
updateModsBtn.classList.add('hidden');
|
||||
}
|
||||
if (backupBtn) {
|
||||
backupBtn.classList.add('hidden');
|
||||
}
|
||||
if (stopBtn) {
|
||||
stopBtn.disabled = true;
|
||||
stopBtn.classList.add('disabled-btn');
|
||||
@ -467,6 +489,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (updateModsBtn) {
|
||||
updateModsBtn.classList.remove('hidden');
|
||||
}
|
||||
if (backupBtn) {
|
||||
backupBtn.classList.remove('hidden');
|
||||
}
|
||||
if (stopBtn) {
|
||||
stopBtn.disabled = false;
|
||||
stopBtn.classList.remove('disabled-btn');
|
||||
@ -1226,7 +1251,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const content = propertiesToString(fullProperties);
|
||||
const response = await wsRequest('/server-properties', 'POST', { content });
|
||||
if (response.error) {
|
||||
updateNotification(notification, `Failed to save server.properties: ${response.error}`, 'error');
|
||||
showNotification(`Failed to save server.properties: ${response.error}`, 'error');
|
||||
return;
|
||||
}
|
||||
elements.editPropertiesModal.classList.add('hidden');
|
||||
@ -1239,15 +1264,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
async function updateMods() {
|
||||
try {
|
||||
const response = await wsRequest('/update-mods', 'POST');
|
||||
console.log('Raw response:', response); // Debug: Log the full response
|
||||
console.log('Output content:', response.output); // Debug: Log the output string
|
||||
if (response.error) {
|
||||
showNotification(`Failed to update mods: ${response.error}`, 'error');
|
||||
elements.updateModsOutput.textContent = `Error: ${response.error}`;
|
||||
} else {
|
||||
const output = response.output || 'No output from mod update.';
|
||||
console.log('Processed output:', output); // Debug: Log the final output
|
||||
elements.updateModsOutput.textContent = output; // Set textContent
|
||||
elements.updateModsOutput.textContent = output;
|
||||
}
|
||||
elements.updateModsModal.classList.remove('hidden');
|
||||
} catch (error) {
|
||||
@ -1258,6 +1280,32 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function createBackup() {
|
||||
try {
|
||||
showNotification('Your backup is being created, a download will begin once ready!', 'success');
|
||||
const response = await wsRequest('/backup', 'POST');
|
||||
if (response.error) {
|
||||
showNotification(`Failed to create backup: ${response.error}`, 'error');
|
||||
return;
|
||||
}
|
||||
const downloadURL = response.downloadURL;
|
||||
if (downloadURL) {
|
||||
const link = document.createElement('a');
|
||||
link.href = downloadURL;
|
||||
link.download = ''; // Let the browser infer the filename from the URL
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
showNotification('Backup download initiated', 'success');
|
||||
} else {
|
||||
showNotification('Backup created but no download URL provided', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Create backup error:', error);
|
||||
showNotification(`Failed to create backup: ${error.message}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
elements.loginBtn.addEventListener('click', () => {
|
||||
apiKey = elements.loginApiKey.value.trim();
|
||||
if (apiKey) {
|
||||
@ -1314,21 +1362,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
initializeTerminal();
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
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
|
||||
ws.removeEventListener('message', messageHandler);
|
||||
}
|
||||
} 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);
|
||||
@ -1336,7 +1382,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
updateNotification(notification, 'Server failed to start', 'error');
|
||||
}
|
||||
}
|
||||
}, 30000); // 30 seconds timeout
|
||||
}, 30000);
|
||||
} else {
|
||||
updateNotification(notification, 'WebSocket not connected', 'error');
|
||||
}
|
||||
@ -1378,6 +1424,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
elements.updateModsOutput.textContent = '';
|
||||
});
|
||||
|
||||
elements.backupBtn.addEventListener('click', createBackup);
|
||||
|
||||
document.getElementById('searchBtn').addEventListener('click', () => {
|
||||
searchMods(1);
|
||||
});
|
||||
|
@ -104,6 +104,7 @@
|
||||
<h1 class="text-2xl font-bold">My-MC Server Panel</h1>
|
||||
<div class="flex space-x-4">
|
||||
<button id="refresh" class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded">Refresh</button>
|
||||
<button id="backupBtn" class="bg-purple-600 hover:bg-purple-700 px-4 py-2 rounded">Backup</button>
|
||||
<div id="authControls">
|
||||
<input id="apiKey" type="text" placeholder="Enter API Key" class="bg-gray-700 px-4 py-2 rounded text-white">
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user