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

@@ -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);
}