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:
parent
315afea3f4
commit
d477d65ff5
@ -31,6 +31,7 @@
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"morgan": "^1.10.0",
|
||||
"node-fetch": "^2.6.11",
|
||||
"semver": "^7.5.4",
|
||||
"transmission-promise": "^1.1.5",
|
||||
"xml2js": "^0.5.0"
|
||||
},
|
||||
|
@ -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 {
|
||||
|
12
server.js
12
server.js
@ -25,6 +25,10 @@ const DEFAULT_PORT = 3000;
|
||||
const JWT_SECRET = process.env.JWT_SECRET || 'transmission-rss-manager-secret';
|
||||
const JWT_EXPIRY = '24h';
|
||||
|
||||
// Get the version from package.json (single source of truth)
|
||||
const PACKAGE_JSON = require('./package.json');
|
||||
const APP_VERSION = PACKAGE_JSON.version;
|
||||
|
||||
// Create Express app
|
||||
const app = express();
|
||||
|
||||
@ -92,7 +96,7 @@ async function loadConfig() {
|
||||
try {
|
||||
// Define default configuration
|
||||
const defaultConfig = {
|
||||
version: '2.0.0',
|
||||
version: APP_VERSION, // Use the version from package.json
|
||||
transmissionConfig: {
|
||||
host: 'localhost',
|
||||
port: 9091,
|
||||
@ -152,9 +156,9 @@ async function loadConfig() {
|
||||
const mergedConfig = mergeConfigs(defaultConfig, loadedConfig);
|
||||
|
||||
// If version is different, save updated config
|
||||
if (loadedConfig.version !== defaultConfig.version) {
|
||||
console.log(`Updating config from version ${loadedConfig.version || 'unknown'} to ${defaultConfig.version}`);
|
||||
mergedConfig.version = defaultConfig.version;
|
||||
if (loadedConfig.version !== APP_VERSION) {
|
||||
console.log(`Updating config from version ${loadedConfig.version || 'unknown'} to ${APP_VERSION}`);
|
||||
mergedConfig.version = APP_VERSION;
|
||||
await saveConfig(mergedConfig);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user