119 lines
3.0 KiB
Plaintext
119 lines
3.0 KiB
Plaintext
// server.js - Main application server file
|
|
const express = require('express');
|
|
const bodyParser = require('body-parser');
|
|
const path = require('path');
|
|
const fs = require('fs').promises;
|
|
const cors = require('cors');
|
|
const Transmission = require('transmission');
|
|
|
|
// Import custom modules
|
|
const PostProcessor = require('./postProcessor');
|
|
const RssFeedManager = require('./rssFeedManager');
|
|
|
|
// Initialize Express app
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Load configuration
|
|
let config = {
|
|
transmissionConfig: {
|
|
host: 'localhost',
|
|
port: 9091,
|
|
username: '',
|
|
password: '',
|
|
path: '/transmission/rpc'
|
|
},
|
|
remoteConfig: {
|
|
isRemote: false,
|
|
directoryMapping: {}
|
|
},
|
|
destinationPaths: {
|
|
movies: '/mnt/media/movies',
|
|
tvShows: '/mnt/media/tvshows',
|
|
music: '/mnt/media/music',
|
|
books: '/mnt/media/books',
|
|
software: '/mnt/media/software'
|
|
},
|
|
seedingRequirements: {
|
|
minRatio: 1.0,
|
|
minTimeMinutes: 60,
|
|
checkIntervalSeconds: 300
|
|
},
|
|
processingOptions: {
|
|
extractArchives: true,
|
|
deleteArchives: true,
|
|
createCategoryFolders: true,
|
|
ignoreSample: true,
|
|
ignoreExtras: true,
|
|
renameFiles: true,
|
|
autoReplaceUpgrades: true,
|
|
removeDuplicates: true,
|
|
keepOnlyBestVersion: true
|
|
},
|
|
rssFeeds: [],
|
|
rssUpdateIntervalMinutes: 60,
|
|
autoProcessing: false
|
|
};
|
|
|
|
// Service instances
|
|
let transmissionClient = null;
|
|
let postProcessor = null;
|
|
let rssFeedManager = null;
|
|
|
|
// Save config function
|
|
async function saveConfig() {
|
|
try {
|
|
await fs.writeFile(
|
|
path.join(__dirname, 'config.json'),
|
|
JSON.stringify(config, null, 2),
|
|
'utf8'
|
|
);
|
|
console.log('Configuration saved');
|
|
return true;
|
|
} catch (err) {
|
|
console.error('Error saving config:', err.message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Load config function
|
|
async function loadConfig() {
|
|
try {
|
|
const data = await fs.readFile(path.join(__dirname, 'config.json'), 'utf8');
|
|
const loadedConfig = JSON.parse(data);
|
|
config = { ...config, ...loadedConfig };
|
|
console.log('Configuration loaded');
|
|
return true;
|
|
} catch (err) {
|
|
console.error('Error loading config, using defaults:', err.message);
|
|
// Save default config
|
|
await saveConfig();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Initialize Transmission client
|
|
function initTransmission() {
|
|
transmissionClient = new Transmission({
|
|
host: config.transmissionConfig.host,
|
|
port: config.transmissionConfig.port,
|
|
username: config.transmissionConfig.username,
|
|
password: config.transmissionConfig.password,
|
|
url: config.transmissionConfig.path
|
|
});
|
|
|
|
console.log(`Transmission client initialized for ${config.transmissionConfig.host}:${config.transmissionConfig.port}`);
|
|
return transmissionClient;
|
|
}
|
|
|
|
// Initialize post processor
|
|
function initPostProcessor() {
|
|
if (postProcessor) {
|
|
postProcessor.stop();
|
|
}
|
|
|
|
postProcessor = new PostProcessor({
|
|
transmissionConfig: config.transmissionConfig,
|
|
remoteConfig: config.remoteConfig,
|
|
destinationPaths: config.destinationPaths,
|
|
see |