diff --git a/src/lib/components/admin/Settings/Database.svelte b/src/lib/components/admin/Settings/Database.svelte index 2a8f221aa5..ea2de29e4d 100644 --- a/src/lib/components/admin/Settings/Database.svelte +++ b/src/lib/components/admin/Settings/Database.svelte @@ -17,6 +17,10 @@ export let saveHandler: Function; let showPruneDataDialog = false; + let showPreviewResults = false; + let previewResults = null; + let lastPruneSettings = null; + const exportAllUserChats = async () => { let blob = new Blob([JSON.stringify(await getAllUserChats(localStorage.token))], { type: 'application/json' @@ -24,48 +28,70 @@ saveAs(blob, `all-chats-export-${Date.now()}.json`); }; - const handlePruneDataConfirm = async (event) => { - const { - days, - exempt_archived_chats, - exempt_chats_in_folders, - delete_orphaned_chats, - delete_orphaned_tools, - delete_orphaned_functions, - delete_orphaned_prompts, - delete_orphaned_knowledge_bases, - delete_orphaned_models, - delete_orphaned_notes, - delete_orphaned_folders, - audio_cache_max_age_days, - delete_inactive_users_days, - exempt_admin_users, - exempt_pending_users - } = event.detail; + const handlePruneDataPreview = async (event) => { + const settings = event.detail; + lastPruneSettings = settings; const res = await pruneData( localStorage.token, - days, - exempt_archived_chats, - exempt_chats_in_folders, - delete_orphaned_chats, - delete_orphaned_tools, - delete_orphaned_functions, - delete_orphaned_prompts, - delete_orphaned_knowledge_bases, - delete_orphaned_models, - delete_orphaned_notes, - delete_orphaned_folders, - audio_cache_max_age_days, - delete_inactive_users_days, - exempt_admin_users, - exempt_pending_users + settings.days, + settings.exempt_archived_chats, + settings.exempt_chats_in_folders, + settings.delete_orphaned_chats, + settings.delete_orphaned_tools, + settings.delete_orphaned_functions, + settings.delete_orphaned_prompts, + settings.delete_orphaned_knowledge_bases, + settings.delete_orphaned_models, + settings.delete_orphaned_notes, + settings.delete_orphaned_folders, + settings.audio_cache_max_age_days, + settings.delete_inactive_users_days, + settings.exempt_admin_users, + settings.exempt_pending_users, + true // dry_run = true for preview ).catch((error) => { toast.error(`${error}`); return null; }); + + if (res) { + previewResults = res; + showPreviewResults = true; + } + }; + + const handleConfirmPrune = async () => { + if (!lastPruneSettings) return; + + const res = await pruneData( + localStorage.token, + lastPruneSettings.days, + lastPruneSettings.exempt_archived_chats, + lastPruneSettings.exempt_chats_in_folders, + lastPruneSettings.delete_orphaned_chats, + lastPruneSettings.delete_orphaned_tools, + lastPruneSettings.delete_orphaned_functions, + lastPruneSettings.delete_orphaned_prompts, + lastPruneSettings.delete_orphaned_knowledge_bases, + lastPruneSettings.delete_orphaned_models, + lastPruneSettings.delete_orphaned_notes, + lastPruneSettings.delete_orphaned_folders, + lastPruneSettings.audio_cache_max_age_days, + lastPruneSettings.delete_inactive_users_days, + lastPruneSettings.exempt_admin_users, + lastPruneSettings.exempt_pending_users, + false // dry_run = false for actual pruning + ).catch((error) => { + toast.error(`${error}`); + return null; + }); + if (res) { toast.success('Data pruned successfully'); + showPreviewResults = false; + previewResults = null; + lastPruneSettings = null; } }; @@ -97,7 +123,151 @@ }); - + +{#if showPreviewResults && previewResults} +
+
+
+

+ {$i18n.t('Pruning Preview Results')} +

+ +
+ +
+
+

+ {$i18n.t('The following items would be deleted:')} +

+
+ {#if previewResults.inactive_users > 0} +
+ {$i18n.t('Inactive users')}: + {previewResults.inactive_users} +
+ {/if} + {#if previewResults.old_chats > 0} +
+ {$i18n.t('Old chats')}: + {previewResults.old_chats} +
+ {/if} + {#if previewResults.orphaned_chats > 0} +
+ {$i18n.t('Orphaned chats')}: + {previewResults.orphaned_chats} +
+ {/if} + {#if previewResults.orphaned_files > 0} +
+ {$i18n.t('Orphaned files')}: + {previewResults.orphaned_files} +
+ {/if} + {#if previewResults.orphaned_tools > 0} +
+ {$i18n.t('Orphaned tools')}: + {previewResults.orphaned_tools} +
+ {/if} + {#if previewResults.orphaned_functions > 0} +
+ {$i18n.t('Orphaned functions')}: + {previewResults.orphaned_functions} +
+ {/if} + {#if previewResults.orphaned_prompts > 0} +
+ {$i18n.t('Orphaned prompts')}: + {previewResults.orphaned_prompts} +
+ {/if} + {#if previewResults.orphaned_knowledge_bases > 0} +
+ {$i18n.t('Orphaned knowledge bases')}: + {previewResults.orphaned_knowledge_bases} +
+ {/if} + {#if previewResults.orphaned_models > 0} +
+ {$i18n.t('Orphaned models')}: + {previewResults.orphaned_models} +
+ {/if} + {#if previewResults.orphaned_notes > 0} +
+ {$i18n.t('Orphaned notes')}: + {previewResults.orphaned_notes} +
+ {/if} + {#if previewResults.orphaned_folders > 0} +
+ {$i18n.t('Orphaned folders')}: + {previewResults.orphaned_folders} +
+ {/if} + {#if previewResults.orphaned_uploads > 0} +
+ {$i18n.t('Orphaned upload files')}: + {previewResults.orphaned_uploads} +
+ {/if} + {#if previewResults.orphaned_vector_collections > 0} +
+ {$i18n.t('Orphaned vector collections')}: + {previewResults.orphaned_vector_collections} +
+ {/if} + {#if previewResults.audio_cache_files > 0} +
+ {$i18n.t('Audio cache files')}: + {previewResults.audio_cache_files} +
+ {/if} +
+ + {#if Object.values(previewResults).every(count => count === 0)} +
+
+ {$i18n.t('No items would be deleted with current settings')} +
+
+ {$i18n.t('Your system is already clean or no cleanup options are enabled')} +
+
+ {/if} +
+ + +
+ + {#if !Object.values(previewResults).every(count => count === 0)} + + {/if} +
+
+
+
+{/if} + +
{