Feat: Updating Mods button
This commit is contained in:
@ -185,4 +185,19 @@ export async function writeServerProperties(docker, containerName, content) {
|
||||
} catch (error) {
|
||||
return { error: `Failed to write server.properties: ${error.message}` };
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateMods(docker, containerName) {
|
||||
try {
|
||||
const container = docker.getContainer(containerName);
|
||||
const inspect = await container.inspect();
|
||||
if (inspect.State.Status !== 'running') {
|
||||
return { error: `Container ${containerName} is not running` };
|
||||
}
|
||||
const { stdout, stderr } = await execPromise(`docker exec ${containerName} bash -c 'cd /home/mc/minecraft && mod-manager update'`);
|
||||
if (stderr) return { output: stderr };
|
||||
return { output: stdout || 'Mod update completed successfully.' };
|
||||
} catch (error) {
|
||||
return { error: `Failed to update mods: ${error.message}` };
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { URLSearchParams } from 'url';
|
||||
import { getContainerStats, streamContainerLogs, readServerProperties, writeServerProperties } from './docker.js';
|
||||
import { getContainerStats, streamContainerLogs, readServerProperties, writeServerProperties, updateMods } from './docker.js';
|
||||
import { checkConnectionStatus, checkGeyserStatus, checkSftpStatus } from './status.js';
|
||||
import { apiRequest } from './api.js';
|
||||
|
||||
@ -481,6 +481,8 @@ export function handleWebSocket(ws, req, docker) {
|
||||
response = client.user === 'Unknown' ? { error: 'User not identified' } : await readServerProperties(docker, client.user);
|
||||
} else if (endpoint === '/server-properties' && method === 'POST' && body && body.content) {
|
||||
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 {
|
||||
response = await apiRequest(endpoint, client.apiKey, method, body);
|
||||
}
|
||||
|
Reference in New Issue
Block a user