Feat: Adding backup button for easy access to download a full server backup

This commit is contained in:
MCHost
2025-06-19 02:36:03 -04:00
parent d2498c0cf8
commit 16d8b52a01
4 changed files with 87 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import { URLSearchParams } from 'url';
import { getContainerStats, streamContainerLogs, readServerProperties, writeServerProperties, updateMods } from './docker.js';
import { getContainerStats, streamContainerLogs, readServerProperties, writeServerProperties, updateMods, createBackup } from './docker.js';
import { checkConnectionStatus, checkGeyserStatus, checkSftpStatus } from './status.js';
import { apiRequest } from './api.js';
@ -42,7 +42,6 @@ function startDockerStatsInterval(ws, client, user, docker) {
const container = docker.getContainer(user);
const inspect = await container.inspect();
if (inspect.State.Status !== 'running') {
// console.log(`Container ${user} not running, sending error`);
ws.send(JSON.stringify({ type: 'docker', error: `Container ${user} is not running` }));
return;
}
@ -247,7 +246,7 @@ async function manageStatusChecks(ws, client, user, docker) {
if (data && data.hostname && data.port) {
const status = await checkFn(data.hostname, data.port);
if (ws.readyState === ws.OPEN) {
ws.send(JSON.stringify({ type: 'connection-status', data: { isOnline: status.isOnline } }));
ws.send(JSON.stringify({ type: statusType, data: { isOnline: status.isOnline } }));
}
}
} catch (error) {
@ -483,6 +482,8 @@ export function handleWebSocket(ws, req, docker) {
response = client.user === 'Unknown' ? { error: 'User not identified' } : await writeServerProperties(docker, client.user, body.content);
} else if (endpoint === '/update-mods' && method === 'POST') {
response = client.user === 'Unknown' ? { error: 'User not identified' } : await updateMods(docker, client.user);
} else if (endpoint === '/backup' && method === 'POST') {
response = client.user === 'Unknown' ? { error: 'User not identified' } : await createBackup(docker, client.user);
} else {
response = await apiRequest(endpoint, client.apiKey, method, body);
}