mirror of https://github.com/VERT-sh/VERT.git
feat: clear site data
This commit is contained in:
parent
0e5f549804
commit
7f3ba14826
|
|
@ -189,7 +189,15 @@
|
|||
"total_size": "Total Size",
|
||||
"files_cached_label": "Files Cached",
|
||||
"cache_cleared": "Cache cleared successfully!",
|
||||
"cache_clear_error": "Failed to clear cache."
|
||||
"cache_clear_error": "Failed to clear cache.",
|
||||
"site_data_title": "Site data management",
|
||||
"site_data_description": "Clear all site data including settings and cached files, resetting VERT to its default state and reloading the page.",
|
||||
"clear_all_data": "Clear all site data",
|
||||
"clear_all_data_confirm_title": "Clear all site data?",
|
||||
"clear_all_data_confirm": "This will reset all settings & cache, then reload the page. This action cannot be undone.",
|
||||
"clear_all_data_cancel": "Cancel",
|
||||
"all_data_cleared": "All site data cleared! Reloading page...",
|
||||
"all_data_clear_error": "Failed to clear all site data."
|
||||
},
|
||||
"language": {
|
||||
"title": "Language",
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
import { error } from "$lib/logger";
|
||||
import { ToastManager } from "$lib/toast/index.svelte";
|
||||
import { DISABLE_ALL_EXTERNAL_REQUESTS } from "$lib/consts";
|
||||
import { addDialog } from "$lib/store/DialogProvider";
|
||||
|
||||
const { settings = $bindable() }: { settings: ISettings } = $props();
|
||||
|
||||
|
|
@ -66,6 +67,57 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function clearAllData() {
|
||||
if (isLoadingCache) return;
|
||||
|
||||
addDialog(
|
||||
m["settings.privacy.clear_all_data_confirm_title"](),
|
||||
m["settings.privacy.clear_all_data_confirm"](),
|
||||
[
|
||||
{
|
||||
text: m["settings.privacy.clear_all_data_cancel"](),
|
||||
action: () => {},
|
||||
},
|
||||
{
|
||||
text: m["settings.privacy.clear_all_data"](),
|
||||
action: async () => {
|
||||
isLoadingCache = true;
|
||||
try {
|
||||
await swManager.clearCache();
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
|
||||
ToastManager.add({
|
||||
type: "success",
|
||||
message:
|
||||
m["settings.privacy.all_data_cleared"](),
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = "/";
|
||||
}, 1500);
|
||||
} catch (err) {
|
||||
error(
|
||||
["privacy", "data"],
|
||||
`Failed to clear all data: ${err}`,
|
||||
);
|
||||
ToastManager.add({
|
||||
type: "error",
|
||||
message:
|
||||
m[
|
||||
"settings.privacy.all_data_clear_error"
|
||||
](),
|
||||
});
|
||||
} finally {
|
||||
isLoadingCache = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
"warning",
|
||||
);
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
loadCacheInfo();
|
||||
});
|
||||
|
|
@ -195,6 +247,28 @@
|
|||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-col gap-2">
|
||||
<p class="text-base font-bold">
|
||||
{m["settings.privacy.site_data_title"]()}
|
||||
</p>
|
||||
<p class="text-sm text-muted font-normal">
|
||||
{m["settings.privacy.site_data_description"]()}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onclick={clearAllData}
|
||||
class="btn {$effects
|
||||
? ''
|
||||
: '!scale-100'} w-full p-4 rounded-lg text-black dynadark:text-white flex items-center justify-center"
|
||||
disabled={isLoadingCache}
|
||||
>
|
||||
<Trash2Icon size="24" class="inline-block mr-2" />
|
||||
{m["settings.privacy.clear_all_data"]()}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div></Panel
|
||||
>
|
||||
|
|
|
|||
Loading…
Reference in New Issue