mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-09-10 09:35:39 +00:00
a6ec256f57
Added a new API endpoint to retrieve the last update result, enhancing the user interface by displaying detailed error messages for failed updates. Improved the update completion modal to reflect the status of services and console restarts, ensuring users are informed of any issues. Updated the settings JavaScript to load and display the last update result dynamically, improving overall user experience during updates.
99 lines
2.9 KiB
JavaScript
99 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const NON_CRITICAL_UPDATE_FAILURES = new Set([
|
|
'betterdesk-server',
|
|
'betterdesk-server-deploy',
|
|
'betterdesk-server.service',
|
|
'server-source',
|
|
'npm install',
|
|
'support-agent-source-sync',
|
|
'betterdesk.sh',
|
|
'betterdesk.ps1',
|
|
'betterdesk-docker.sh',
|
|
'docker-compose.yml',
|
|
'docker-compose.single.yml',
|
|
'docker-compose.quick.yml',
|
|
'Dockerfile',
|
|
'Dockerfile.server',
|
|
'Dockerfile.console',
|
|
]);
|
|
|
|
function isNonCriticalUpdateFailure(fileKey) {
|
|
return NON_CRITICAL_UPDATE_FAILURES.has(fileKey);
|
|
}
|
|
|
|
function localPathFromFailureFile(fileKey) {
|
|
if (!fileKey || typeof fileKey !== 'string') return '';
|
|
return fileKey.startsWith('web-nodejs/') ? fileKey.slice('web-nodejs/'.length) : fileKey;
|
|
}
|
|
|
|
/** Repair step asked for a path Node never loads (routes.js, duplicated scripts/). */
|
|
function isPhantomRepairFailure(fileKey, rootDir) {
|
|
const localPath = localPathFromFailureFile(fileKey);
|
|
if (!localPath || !rootDir) return false;
|
|
if (localPath === 'routes.js') {
|
|
return fs.existsSync(path.join(rootDir, 'routes', 'index.js'));
|
|
}
|
|
if (/^scripts\/scripts\//.test(localPath)) return true;
|
|
if (localPath.endsWith('.js')) {
|
|
const indexPath = path.join(rootDir, `${localPath.slice(0, -3)}`, 'index.js');
|
|
if (fs.existsSync(indexPath)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function isFailureNonCritical(entry, rootDir) {
|
|
if (!entry) return false;
|
|
if (entry.nonCritical) return true;
|
|
if (isNonCriticalUpdateFailure(entry.file)) return true;
|
|
if (entry.file === 'npm install' && entry.nodeModulesOk) return true;
|
|
if (isPhantomRepairFailure(entry.file, rootDir)) return true;
|
|
return false;
|
|
}
|
|
|
|
function splitUpdateFailures(failed, rootDir) {
|
|
const critical = [];
|
|
const nonCritical = [];
|
|
for (const entry of failed || []) {
|
|
if (isFailureNonCritical(entry, rootDir)) nonCritical.push(entry);
|
|
else critical.push(entry);
|
|
}
|
|
return { critical, nonCritical };
|
|
}
|
|
|
|
function canScheduleConsoleRestart(result, dataDir) {
|
|
if (!result?.needsConsoleRestart) {
|
|
return { allowed: false };
|
|
}
|
|
const patch = result.servicePatch || {};
|
|
if (patch.consolePermissionsOk !== false) {
|
|
return { allowed: true };
|
|
}
|
|
try {
|
|
fs.accessSync(dataDir, fs.constants.W_OK);
|
|
return {
|
|
allowed: true,
|
|
note: 'Console data directory is writable — restart allowed despite permission-sync warning',
|
|
};
|
|
} catch (_) {
|
|
return {
|
|
allowed: false,
|
|
blockedReason: patch.consoleUserError
|
|
|| `Console data directory is not writable: ${dataDir}`,
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
NON_CRITICAL_UPDATE_FAILURES,
|
|
isNonCriticalUpdateFailure,
|
|
isPhantomRepairFailure,
|
|
isFailureNonCritical,
|
|
splitUpdateFailures,
|
|
canScheduleConsoleRestart,
|
|
localPathFromFailureFile,
|
|
};
|