Enhanced setup and settings pages with full configuration
- 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
This commit is contained in:
@@ -20,31 +20,55 @@ AniWorld.MainConfig = (function() {
|
||||
async function save() {
|
||||
try {
|
||||
const animeDirectory = document.getElementById('anime-directory-input').value.trim();
|
||||
const appName = document.getElementById('app-name-input').value.trim();
|
||||
const dataDir = document.getElementById('data-dir-input').value.trim();
|
||||
|
||||
if (!animeDirectory) {
|
||||
AniWorld.UI.showToast('Please enter an anime directory path', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await AniWorld.ApiClient.post(API.CONFIG_DIRECTORY, {
|
||||
directory: animeDirectory
|
||||
});
|
||||
// Get current config
|
||||
const currentConfig = await loadCurrentConfig();
|
||||
if (!currentConfig) {
|
||||
AniWorld.UI.showToast('Failed to load current configuration', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Update fields
|
||||
if (appName) currentConfig.name = appName;
|
||||
if (dataDir) currentConfig.data_dir = dataDir;
|
||||
if (!currentConfig.other) currentConfig.other = {};
|
||||
currentConfig.other.anime_directory = animeDirectory;
|
||||
|
||||
// Save updated config
|
||||
const response = await AniWorld.ApiClient.put(AniWorld.Constants.API.CONFIG, currentConfig);
|
||||
|
||||
if (!response) return;
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
AniWorld.UI.showToast('Main configuration saved successfully', 'success');
|
||||
await refreshStatus();
|
||||
} else {
|
||||
AniWorld.UI.showToast('Failed to save configuration: ' + data.error, 'error');
|
||||
}
|
||||
AniWorld.UI.showToast('Main configuration saved successfully', 'success');
|
||||
await refreshStatus();
|
||||
} catch (error) {
|
||||
console.error('Error saving main config:', error);
|
||||
AniWorld.UI.showToast('Failed to save main configuration', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load current configuration from API
|
||||
*/
|
||||
async function loadCurrentConfig() {
|
||||
try {
|
||||
const response = await AniWorld.ApiClient.get(AniWorld.Constants.API.CONFIG);
|
||||
if (!response) return null;
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error loading config:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset main configuration
|
||||
*/
|
||||
@@ -109,12 +133,45 @@ AniWorld.MainConfig = (function() {
|
||||
*/
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const response = await AniWorld.ApiClient.get(API.ANIME_STATUS);
|
||||
if (!response) return;
|
||||
const data = await response.json();
|
||||
// Load full configuration
|
||||
const config = await loadCurrentConfig();
|
||||
if (!config) return;
|
||||
|
||||
document.getElementById('anime-directory-input').value = data.directory || '';
|
||||
document.getElementById('series-count-input').value = data.series_count || '0';
|
||||
// Populate general settings
|
||||
document.getElementById('app-name-input').value = config.name || 'Aniworld';
|
||||
document.getElementById('data-dir-input').value = config.data_dir || 'data';
|
||||
document.getElementById('anime-directory-input').value = config.other?.anime_directory || '';
|
||||
|
||||
// Populate scheduler settings
|
||||
document.getElementById('scheduled-rescan-enabled').checked = config.scheduler?.enabled || false;
|
||||
document.getElementById('scheduled-rescan-interval').value = config.scheduler?.interval_minutes || 60;
|
||||
|
||||
// Populate logging settings
|
||||
document.getElementById('log-level').value = config.logging?.level || 'INFO';
|
||||
document.getElementById('log-file').value = config.logging?.file || '';
|
||||
document.getElementById('log-max-bytes').value = config.logging?.max_bytes || '';
|
||||
document.getElementById('log-backup-count').value = config.logging?.backup_count || 3;
|
||||
|
||||
// Populate backup settings
|
||||
document.getElementById('backup-enabled').checked = config.backup?.enabled || false;
|
||||
document.getElementById('backup-path').value = config.backup?.path || 'data/backups';
|
||||
document.getElementById('backup-keep-days').value = config.backup?.keep_days || 30;
|
||||
|
||||
// Populate NFO settings
|
||||
document.getElementById('tmdb-api-key').value = config.nfo?.tmdb_api_key || '';
|
||||
document.getElementById('nfo-auto-create').checked = config.nfo?.auto_create || false;
|
||||
document.getElementById('nfo-update-on-scan').checked = config.nfo?.update_on_scan || false;
|
||||
document.getElementById('nfo-download-poster').checked = config.nfo?.download_poster !== false;
|
||||
document.getElementById('nfo-download-logo').checked = config.nfo?.download_logo !== false;
|
||||
document.getElementById('nfo-download-fanart').checked = config.nfo?.download_fanart !== false;
|
||||
document.getElementById('nfo-image-size').value = config.nfo?.image_size || 'original';
|
||||
|
||||
// Get series count from status endpoint
|
||||
const statusResponse = await AniWorld.ApiClient.get(API.ANIME_STATUS);
|
||||
if (statusResponse) {
|
||||
const statusData = await statusResponse.json();
|
||||
document.getElementById('series-count-input').value = statusData.series_count || '0';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error refreshing status:', error);
|
||||
}
|
||||
@@ -278,6 +335,36 @@ AniWorld.MainConfig = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save backup configuration
|
||||
*/
|
||||
async function saveBackupConfig() {
|
||||
try {
|
||||
const config = await loadCurrentConfig();
|
||||
if (!config) {
|
||||
AniWorld.UI.showToast('Failed to load current configuration', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Update backup settings
|
||||
config.backup = {
|
||||
enabled: document.getElementById('backup-enabled').checked,
|
||||
path: document.getElementById('backup-path').value.trim(),
|
||||
keep_days: parseInt(document.getElementById('backup-keep-days').value) || 30
|
||||
};
|
||||
|
||||
// Save updated config
|
||||
const response = await AniWorld.ApiClient.put(AniWorld.Constants.API.CONFIG, config);
|
||||
|
||||
if (!response) return;
|
||||
|
||||
AniWorld.UI.showToast('Backup configuration saved successfully', 'success');
|
||||
} catch (error) {
|
||||
console.error('Error saving backup config:', error);
|
||||
AniWorld.UI.showToast('Failed to save backup configuration', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
return {
|
||||
save: save,
|
||||
@@ -289,6 +376,7 @@ AniWorld.MainConfig = (function() {
|
||||
viewBackups: viewBackups,
|
||||
exportConfig: exportConfig,
|
||||
validateConfig: validateConfig,
|
||||
resetAllConfig: resetAllConfig
|
||||
resetAllConfig: resetAllConfig,
|
||||
saveBackupConfig: saveBackupConfig
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user