This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-15 00:14:01 -04:00
1 parent 254888cf15
commit 63ada24706
31 files changed
+2560 -2754

No files matched your search

@@ -3,17 +3,20 @@
const { saveAs } = fileSaver;
import { downloadDatabase } from '$lib/apis/utils';
import { onMount, getContext } from 'svelte';
import { config, user } from '$lib/stores';
import { getContext } from 'svelte';
import { config } from '$lib/stores';
import { toast } from 'svelte-sonner';
import { getAllUserChats } from '$lib/apis/chats';
import { getAllUsers } from '$lib/apis/users';
import { exportConfig, importConfig } from '$lib/apis/configs';
const i18n = getContext('i18n');
const i18n: any = getContext('i18n');
export let saveHandler: Function;
const actionButtonClass =
'rounded-md px-1.5 py-0.5 text-xs text-gray-500 transition-colors hover:bg-black/5 hover:text-gray-900 dark:text-gray-500 dark:hover:bg-white/5 dark:hover:text-white';
const exportAllUserChats = async () => {
let blob = new Blob([JSON.stringify(await getAllUserChats(localStorage.token))], {
type: 'application/json'
@@ -43,14 +46,10 @@
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
saveAs(blob, 'users.csv');
};
onMount(async () => {
// permissions = await getUserPermissions(localStorage.token);
});
</script>
<div class="flex flex-col h-full justify-between text-sm">
<div class="space-y-3 flex-1 min-h-0 overflow-y-auto scrollbar-hover pr-1.5 -mr-1.5">
<div class="flex-1 min-h-0 overflow-y-auto scrollbar-hover pr-1.5">
<input
id="config-json-input"
hidden
@@ -77,29 +76,24 @@
}}
/>
<div>
<div class="mb-1 text-sm font-normal">{$i18n.t('Config')}</div>
<div>
<div class="py-0.5 flex w-full justify-between">
<div class="self-center text-xs">{$i18n.t('Import Config')}</div>
<div class="flex w-full flex-col gap-2.5">
<div class="flex items-center gap-2">
<div class="w-24 shrink-0 text-xs text-gray-600 dark:text-gray-400">
{$i18n.t('Config')}
</div>
<div class="flex flex-wrap items-center gap-1">
<button
class="p-1 px-3 text-xs flex rounded-sm transition"
class={actionButtonClass}
on:click={() => {
document.getElementById('config-json-input').click();
document.getElementById('config-json-input')?.click();
}}
type="button"
>
<span class="self-center">{$i18n.t('Import')}</span>
{$i18n.t('Import')}
</button>
</div>
</div>
<div>
<div class="py-0.5 flex w-full justify-between">
<div class="self-center text-xs">{$i18n.t('Export Config')}</div>
<button
class="p-1 px-3 text-xs flex rounded-sm transition"
class={actionButtonClass}
on:click={async () => {
const config = await exportConfig(localStorage.token);
const blob = new Blob([JSON.stringify(config)], {
@@ -109,63 +103,47 @@
}}
type="button"
>
<span class="self-center">{$i18n.t('Export')}</span>
{$i18n.t('Export')}
</button>
</div>
</div>
{#if $config?.features.enable_admin_export ?? true}
<div class="flex items-center gap-2">
<div class="w-24 shrink-0 text-xs text-gray-600 dark:text-gray-400">
{$i18n.t('Database')}
</div>
<button
class={actionButtonClass}
on:click={() => {
downloadDatabase(localStorage.token).catch((error) => {
toast.error(`${error}`);
});
}}
type="button"
>
{$i18n.t('Download')}
</button>
</div>
<div class="flex items-center gap-2">
<div class="w-24 shrink-0 text-xs text-gray-600 dark:text-gray-400">
{$i18n.t('All chats')}
</div>
<button class={actionButtonClass} on:click={exportAllUserChats} type="button">
{$i18n.t('Export')}
</button>
</div>
<div class="flex items-center gap-2">
<div class="w-24 shrink-0 text-xs text-gray-600 dark:text-gray-400">
{$i18n.t('Users')}
</div>
<button class={actionButtonClass} on:click={exportUsers} type="button">
{$i18n.t('Export')}
</button>
</div>
{/if}
</div>
{#if $config?.features.enable_admin_export ?? true}
<div>
<div class="mb-1 text-sm font-normal">{$i18n.t('Database')}</div>
<div>
<div class="py-0.5 flex w-full justify-between">
<div class="self-center text-xs">{$i18n.t('Download Database')}</div>
<button
class="p-1 px-3 text-xs flex rounded-sm transition"
on:click={() => {
downloadDatabase(localStorage.token).catch((error) => {
toast.error(`${error}`);
});
}}
type="button"
>
<span class="self-center">{$i18n.t('Download')}</span>
</button>
</div>
</div>
<div>
<div class="py-0.5 flex w-full justify-between">
<div class="self-center text-xs">{$i18n.t('Export All Chats (All Users)')}</div>
<button
class="p-1 px-3 text-xs flex rounded-sm transition"
on:click={() => {
exportAllUserChats();
}}
type="button"
>
<span class="self-center">{$i18n.t('Export')}</span>
</button>
</div>
</div>
<div>
<div class="py-0.5 flex w-full justify-between">
<div class="self-center text-xs">{$i18n.t('Export Users')}</div>
<button
class="p-1 px-3 text-xs flex rounded-sm transition"
on:click={() => {
exportUsers();
}}
type="button"
>
<span class="self-center">{$i18n.t('Export')}</span>
</button>
</div>
</div>
</div>
{/if}
</div>
</div>