open-webui/src/lib/apis/prune.ts
Classic298 60d7ad22ee
Claude/vacuum optional 011 c uw61vf5 s rym bh cw u1 ls w (#28)
PruneLock class
Vector cleanup error reporting
Lock acquisition/release
Optional VACUUM
Fixed folder deletion
2025-11-10 17:14:27 +01:00

66 lines
1.8 KiB
TypeScript

import { WEBUI_API_BASE_URL } from '$lib/constants';
export const pruneData = async (
token: string,
days: number | null,
exempt_archived_chats: boolean,
exempt_chats_in_folders: boolean,
delete_orphaned_chats: boolean = true,
delete_orphaned_tools: boolean = false,
delete_orphaned_functions: boolean = false,
delete_orphaned_prompts: boolean = true,
delete_orphaned_knowledge_bases: boolean = true,
delete_orphaned_models: boolean = true,
delete_orphaned_notes: boolean = true,
delete_orphaned_folders: boolean = true,
audio_cache_max_age_days: number | null = 30,
delete_inactive_users_days: number | null = null,
exempt_admin_users: boolean = true,
exempt_pending_users: boolean = true,
run_vacuum: boolean = false,
dry_run: boolean // Removed default value to ensure explicit passing
) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/prune/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({
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,
run_vacuum,
dry_run
})
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err;
console.log(err);
return null;
});
if (error) {
throw error;
}
return res;
};