Fix code consistency and reliability issues

This commit addresses multiple code consistency and reliability issues across the codebase:

1. Version consistency - use package.json version (2.0.9) throughout
2. Improved module loading with better error handling and consistent symlinks
3. Enhanced data directory handling with better error checking
4. Fixed redundant code in main-installer.sh
5. Improved error handling in transmission-client.js
6. Added extensive module symlink creation
7. Better file path handling and permission checks
8. Enhanced API response handling

💡 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-03-07 11:38:14 +00:00
parent 83222078d9
commit 6dc2df3cee
8 changed files with 268 additions and 112 deletions
+43 -41
View File
@@ -21,60 +21,62 @@ const semver = require('semver'); // For semantic version comparison
// Import custom modules
let RssFeedManager, TransmissionClient, PostProcessor;
// Helper function to try multiple module paths
function tryRequire(modulePaths) {
/**
* Helper function to try multiple module paths
* This function tries to require a module using different naming conventions
* to work around issues with module resolution in different Node.js environments
*
* @param {string} baseName - The base module name without extension or path
* @returns {Object} The loaded module
* @throws {Error} If module cannot be loaded from any path
*/
function loadModule(baseName) {
// Generate all possible module paths
const paths = [
`./modules/${baseName}.js`, // With extension
`./modules/${baseName}`, // Without extension
// Convert hyphenated to camelCase
`./modules/${baseName.replace(/-([a-z])/g, (_, c) => c.toUpperCase())}.js`,
`./modules/${baseName.replace(/-([a-z])/g, (_, c) => c.toUpperCase())}`,
// Convert camelCase to hyphenated
`./modules/${baseName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()}.js`,
`./modules/${baseName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()}`
];
let lastError = null;
for (const modulePath of modulePaths) {
for (const modulePath of paths) {
try {
return require(modulePath);
} catch (err) {
console.log(`Attempted to load module from ${modulePath}, but got error: ${err.message}`);
if (err.code !== 'MODULE_NOT_FOUND' || !err.message.includes(modulePath)) {
// This is a real error in the module, not just not finding it
throw err;
}
lastError = err;
}
}
throw lastError;
// If we get here, we couldn't load the module from any path
const error = new Error(`Could not load module '${baseName}' from any path. Original error: ${lastError.message}`);
error.original = lastError;
throw error;
}
// Try loading modules with various namings (with and without .js extension, with hyphens or camelCase)
// Try loading modules with improved error reporting
try {
const rssPaths = [
'./modules/rss-feed-manager.js',
'./modules/rssFeedManager.js',
'./modules/rss-feed-manager',
'./modules/rssFeedManager'
];
RssFeedManager = tryRequire(rssPaths);
RssFeedManager = loadModule('rss-feed-manager');
console.log('Successfully loaded RssFeedManager module');
} catch (err) {
console.error('Failed to load RssFeedManager module:', err);
process.exit(1);
}
try {
const transmissionPaths = [
'./modules/transmission-client.js',
'./modules/transmissionClient.js',
'./modules/transmission-client',
'./modules/transmissionClient'
];
TransmissionClient = tryRequire(transmissionPaths);
TransmissionClient = loadModule('transmission-client');
console.log('Successfully loaded TransmissionClient module');
} catch (err) {
console.error('Failed to load TransmissionClient module:', err);
process.exit(1);
}
try {
const processorPaths = [
'./modules/post-processor.js',
'./modules/postProcessor.js',
'./modules/post-processor',
'./modules/postProcessor'
];
PostProcessor = tryRequire(processorPaths);
PostProcessor = loadModule('post-processor');
console.log('Successfully loaded PostProcessor module');
} catch (err) {
console.error('Failed to load PostProcessor module:', err);
console.error('Fatal error loading required module:', err.message);
console.error('Please make sure all module files exist and are valid JavaScript');
process.exit(1);
}
@@ -456,7 +458,7 @@ app.get('/api/status', authenticateJWT, async (req, res) => {
res.json({
success: true,
status: 'running',
version: '2.0.6',
version: APP_VERSION, // Use the dynamic APP_VERSION from package.json
transmissionConnected: transmissionStatus.connected,
transmissionVersion: transmissionStatus.version,
transmissionStats: {