Implement improved version handling and semantic versioning

- Add semver library for semantic version comparison
- Make package.json the single source of truth for version
- Add version check to only offer updates when remote version is higher
- Use APP_VERSION constant throughout server instead of hardcoded values
- Refactor update checking logic to use semver.gt() for proper comparison

This change improves robustness by ensuring updates are only
offered when a higher semantic version is available in the repository.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-03-05 00:20:50 +00:00
parent 315afea3f4
commit d477d65ff5
3 changed files with 18 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ const { promisify } = require('util');
const execAsync = promisify(exec);
const fs = require('fs');
const path = require('path');
const semver = require('semver'); // Add this - for semantic version comparison
// Add these endpoints
@@ -60,9 +61,8 @@ app.get('/api/system/check-updates', async (req, res) => {
});
}
// Get current version
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
const currentVersion = packageJson.version;
// Get current version from the global APP_VERSION constant
const currentVersion = APP_VERSION;
// Check for test mode flag which forces update availability for testing
const testMode = req.query.test === 'true';
@@ -94,13 +94,17 @@ app.get('/api/system/check-updates', async (req, res) => {
const remotePackage = JSON.parse(remotePackageJson);
const remoteVersion = remotePackage.version;
// Compare versions semantically - only consider it an update if remote version is higher
const isNewerVersion = semver.gt(remoteVersion, currentVersion);
return res.json({
status: 'success',
data: {
updateAvailable: true,
updateAvailable: isNewerVersion,
currentVersion,
remoteVersion,
commitsBehind: behindCount
commitsBehind: behindCount,
newerVersion: isNewerVersion
}
});
} else {