diff --git a/package.json b/package.json index 2f0bd94..fa22f2a 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/server-endpoints.js b/server-endpoints.js index d2a6d57..4dc45ea 100644 --- a/server-endpoints.js +++ b/server-endpoints.js @@ -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 { diff --git a/server.js b/server.js index 0f3ad8d..1b028d5 100644 --- a/server.js +++ b/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); }