- Extended SetupRequest model to include all configuration fields - Updated setup API endpoint to handle comprehensive configuration - Created new setup.html with organized configuration sections - Enhanced config modal in index.html with all settings - Updated JavaScript modules to use unified config API - Added backup configuration section - Documented new features in features.md and instructions.md
126 lines
4.3 KiB
JavaScript
126 lines
4.3 KiB
JavaScript
/**
|
|
* AniWorld - Scheduler Config Module
|
|
*
|
|
* Handles scheduler configuration and scheduled rescan settings.
|
|
*
|
|
* Dependencies: constants.js, api-client.js, ui-utils.js
|
|
*/
|
|
|
|
var AniWorld = window.AniWorld || {};
|
|
|
|
AniWorld.SchedulerConfig = (function() {
|
|
'use strict';
|
|
|
|
const API = AniWorld.Constants.API;
|
|
|
|
/**
|
|
* Load scheduler configuration
|
|
*/
|
|
async function load() {
|
|
try {
|
|
const response = await AniWorld.ApiClient.get(API.SCHEDULER_CONFIG);
|
|
if (!response) return;
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
const config = data.config;
|
|
|
|
// Update UI elements
|
|
document.getElementById('scheduled-rescan-enabled').checked = config.enabled;
|
|
document.getElementById('scheduled-rescan-time').value = config.time || '03:00';
|
|
document.getElementById('auto-download-after-rescan').checked = config.auto_download_after_rescan;
|
|
|
|
// Update status display
|
|
document.getElementById('next-rescan-time').textContent =
|
|
config.next_run ? new Date(config.next_run).toLocaleString() : 'Not scheduled';
|
|
document.getElementById('last-rescan-time').textContent =
|
|
config.last_run ? new Date(config.last_run).toLocaleString() : 'Never';
|
|
|
|
const statusBadge = document.getElementById('scheduler-running-status');
|
|
statusBadge.textContent = config.is_running ? 'Running' : 'Stopped';
|
|
statusBadge.className = 'info-value status-badge ' + (config.is_running ? 'running' : 'stopped');
|
|
|
|
// Enable/disable time input based on checkbox
|
|
toggleTimeInput();
|
|
}
|
|
} catch (error) {
|
|
console.error('Error loading scheduler config:', error);
|
|
AniWorld.UI.showToast('Failed to load scheduler configuration', 'error');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save scheduler configuration
|
|
*/
|
|
async function save() {
|
|
try {
|
|
const enabled = document.getElementById('scheduled-rescan-enabled').checked;
|
|
const interval = parseInt(document.getElementById('scheduled-rescan-interval').value) || 60;
|
|
|
|
// Get current config
|
|
const configResponse = await AniWorld.ApiClient.get(AniWorld.Constants.API.CONFIG);
|
|
if (!configResponse) return;
|
|
const config = await configResponse.json();
|
|
|
|
// Update scheduler settings
|
|
config.scheduler = {
|
|
enabled: enabled,
|
|
interval_minutes: interval
|
|
};
|
|
|
|
// Save updated config
|
|
const response = await AniWorld.ApiClient.put(AniWorld.Constants.API.CONFIG, config);
|
|
if (!response) return;
|
|
|
|
AniWorld.UI.showToast('Scheduler configuration saved successfully', 'success');
|
|
await load();
|
|
} catch (error) {
|
|
console.error('Error saving scheduler config:', error);
|
|
AniWorld.UI.showToast('Failed to save scheduler configuration', 'error');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test scheduled rescan
|
|
*/
|
|
async function testRescan() {
|
|
try {
|
|
const response = await AniWorld.ApiClient.post(API.SCHEDULER_TRIGGER, {});
|
|
|
|
if (!response) return;
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
AniWorld.UI.showToast('Test rescan triggered successfully', 'success');
|
|
} else {
|
|
AniWorld.UI.showToast('Failed to trigger test rescan: ' + data.error, 'error');
|
|
}
|
|
} catch (error) {
|
|
console.error('Error triggering test rescan:', error);
|
|
AniWorld.UI.showToast('Failed to trigger test rescan', 'error');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Toggle scheduler time input visibility
|
|
*/
|
|
function toggleTimeInput() {
|
|
const enabled = document.getElementById('scheduled-rescan-enabled').checked;
|
|
const timeConfig = document.getElementById('rescan-time-config');
|
|
|
|
if (enabled) {
|
|
timeConfig.classList.add('enabled');
|
|
} else {
|
|
timeConfig.classList.remove('enabled');
|
|
}
|
|
}
|
|
|
|
// Public API
|
|
return {
|
|
load: load,
|
|
save: save,
|
|
testRescan: testRescan,
|
|
toggleTimeInput: toggleTimeInput
|
|
};
|
|
})();
|