Move config file to /etc/transmission-rss-manager

- Changed config location to /etc/transmission-rss-manager/config.json
- Added fallback to maintain backward compatibility
- Updated installers to create and use the new location
- Added installPath property to configuration for updates
- Enhanced documentation with new config location
- Bumped version to 2.0.3

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-03-05 00:48:57 +00:00
parent 3cfc5f3489
commit c495bce21f
7 changed files with 164 additions and 14 deletions
+79 -11
View File
@@ -20,7 +20,8 @@ const TransmissionClient = require('./modules/transmission-client.js');
const PostProcessor = require('./modules/post-processor.js');
// Constants and configuration
const DEFAULT_CONFIG_PATH = path.join(__dirname, 'config.json');
const DEFAULT_CONFIG_PATH = '/etc/transmission-rss-manager/config.json';
const FALLBACK_CONFIG_PATH = path.join(__dirname, 'config.json');
const DEFAULT_PORT = 3000;
const JWT_SECRET = process.env.JWT_SECRET || 'transmission-rss-manager-secret';
const JWT_EXPIRY = '24h';
@@ -97,6 +98,7 @@ async function loadConfig() {
// Define default configuration
const defaultConfig = {
version: APP_VERSION, // Use the version from package.json
installPath: __dirname, // Store the path to the installation directory
transmissionConfig: {
host: 'localhost',
port: 9091,
@@ -147,8 +149,10 @@ async function loadConfig() {
logLevel: "info"
};
// Try primary config location first
try {
// Try to read existing config
// Try to read existing config from primary location
console.log(`Trying to load config from: ${DEFAULT_CONFIG_PATH}`);
const configData = await fs.readFile(DEFAULT_CONFIG_PATH, 'utf8');
const loadedConfig = JSON.parse(configData);
@@ -162,17 +166,68 @@ async function loadConfig() {
await saveConfig(mergedConfig);
}
console.log(`Config loaded from ${DEFAULT_CONFIG_PATH}`);
return mergedConfig;
} catch (readError) {
// If file not found, create default config
if (readError.code === 'ENOENT') {
console.log('Config file not found, creating default configuration');
await saveConfig(defaultConfig);
return defaultConfig;
} catch (primaryError) {
// If file not found in primary location, try fallback location
if (primaryError.code === 'ENOENT') {
console.log(`Config not found at ${DEFAULT_CONFIG_PATH}, trying fallback location...`);
try {
const fallbackData = await fs.readFile(FALLBACK_CONFIG_PATH, 'utf8');
const fallbackConfig = JSON.parse(fallbackData);
// Merge configs
const mergedConfig = mergeConfigs(defaultConfig, fallbackConfig);
// If version is different, save updated config
if (fallbackConfig.version !== APP_VERSION) {
console.log(`Updating config from version ${fallbackConfig.version || 'unknown'} to ${APP_VERSION}`);
mergedConfig.version = APP_VERSION;
}
// Try to save to primary location, but don't fail if we can't
try {
// Create directory if it doesn't exist
await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(mergedConfig, null, 2), 'utf8');
console.log(`Migrated config from ${FALLBACK_CONFIG_PATH} to ${DEFAULT_CONFIG_PATH}`);
} catch (saveError) {
console.warn(`Could not save config to ${DEFAULT_CONFIG_PATH}: ${saveError.message}`);
console.warn('Continuing with fallback config location');
}
console.log(`Config loaded from fallback location: ${FALLBACK_CONFIG_PATH}`);
return mergedConfig;
} catch (fallbackError) {
// If file not found in fallback location, create default config
if (fallbackError.code === 'ENOENT') {
console.log('Config file not found in either location, creating default configuration');
// Try to save to primary location first
try {
await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(defaultConfig, null, 2), 'utf8');
console.log(`Created default config at ${DEFAULT_CONFIG_PATH}`);
} catch (saveError) {
console.warn(`Could not save config to ${DEFAULT_CONFIG_PATH}: ${saveError.message}`);
console.warn('Saving to fallback location instead');
// Save to fallback location instead
await fs.writeFile(FALLBACK_CONFIG_PATH, JSON.stringify(defaultConfig, null, 2), 'utf8');
console.log(`Created default config at ${FALLBACK_CONFIG_PATH}`);
}
return defaultConfig;
}
// For other errors, rethrow
throw fallbackError;
}
}
// For other errors, rethrow
throw readError;
throw primaryError;
}
} catch (error) {
console.error('Error loading configuration:', error);
@@ -231,8 +286,21 @@ function mergeConfigs(defaultConfig, userConfig) {
*/
async function saveConfig(config) {
try {
await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8');
console.log('Configuration saved');
// Always try to save to the primary config location first
try {
// Make sure directory exists
await fs.mkdir(path.dirname(DEFAULT_CONFIG_PATH), { recursive: true });
await fs.writeFile(DEFAULT_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8');
console.log(`Configuration saved to ${DEFAULT_CONFIG_PATH}`);
return;
} catch (primaryError) {
console.warn(`Could not save config to ${DEFAULT_CONFIG_PATH}: ${primaryError.message}`);
console.warn('Trying fallback location...');
// If we couldn't save to the primary location, try the fallback
await fs.writeFile(FALLBACK_CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8');
console.log(`Configuration saved to fallback location: ${FALLBACK_CONFIG_PATH}`);
}
} catch (error) {
console.error('Error saving configuration:', error);
throw error;