fix(server): enable cross-platform update flow and password escaping

This commit is contained in:
Bohdan Triapitsyn
2026-02-10 00:12:44 +02:00
parent 1ed5316ac7
commit 8c42edcf24
+37 -15
View File
@@ -5424,12 +5424,20 @@ async function main(options = {}) {
// Use defaults // Use defaults
} }
const isWindows = process.platform === 'win32';
// Build restart command with stored options // Build restart command with stored options
let restartCmd = `openchamber serve --port ${storedOptions.port} --daemon`; let restartCmd = `openchamber serve --port ${storedOptions.port} --daemon`;
if (storedOptions.uiPassword) { if (storedOptions.uiPassword) {
// Escape password for shell if (isWindows) {
const escapedPw = storedOptions.uiPassword.replace(/'/g, "'\\''"); // Escape for cmd.exe quoted argument
restartCmd += ` --ui-password '${escapedPw}'`; const escapedPw = storedOptions.uiPassword.replace(/"/g, '""');
restartCmd += ` --ui-password "${escapedPw}"`;
} else {
// Escape for POSIX single-quoted argument
const escapedPw = storedOptions.uiPassword.replace(/'/g, "'\\''");
restartCmd += ` --ui-password '${escapedPw}'`;
}
} }
// Respond immediately - update will happen after response // Respond immediately - update will happen after response
@@ -5449,20 +5457,34 @@ async function main(options = {}) {
// 1. Wait for current process to exit // 1. Wait for current process to exit
// 2. Run the update // 2. Run the update
// 3. Restart the server with original options // 3. Restart the server with original options
const script = ` const shell = isWindows ? (process.env.ComSpec || 'cmd.exe') : 'sh';
sleep 2 const shellFlag = isWindows ? '/c' : '-c';
${updateCmd} const script = isWindows
if [ $? -eq 0 ]; then ? `
echo "Update successful, restarting OpenChamber..." timeout /t 2 /nobreak >nul
${restartCmd} ${updateCmd}
else if %ERRORLEVEL% EQU 0 (
echo "Update failed" echo Update successful, restarting OpenChamber...
exit 1 ${restartCmd}
fi ) else (
`; echo Update failed
exit /b 1
)
`
: `
sleep 2
${updateCmd}
if [ $? -eq 0 ]; then
echo "Update successful, restarting OpenChamber..."
${restartCmd}
else
echo "Update failed"
exit 1
fi
`;
// Spawn detached shell to run update after we exit // Spawn detached shell to run update after we exit
const child = spawnChild('sh', ['-c', script], { const child = spawnChild(shell, [shellFlag, script], {
detached: true, detached: true,
stdio: 'ignore', stdio: 'ignore',
env: process.env, env: process.env,