2024-03-02 08:33:20 +00:00
|
|
|
<script lang="ts">
|
2024-05-26 09:43:52 +00:00
|
|
|
import fileSaver from 'file-saver';
|
|
|
|
const { saveAs } = fileSaver;
|
|
|
|
|
2024-03-02 08:33:20 +00:00
|
|
|
import { downloadDatabase } from '$lib/apis/utils';
|
2024-03-02 20:38:51 +00:00
|
|
|
import { onMount, getContext } from 'svelte';
|
2024-05-26 09:43:52 +00:00
|
|
|
import { config, user } from '$lib/stores';
|
2024-04-27 14:53:31 +00:00
|
|
|
import { toast } from 'svelte-sonner';
|
2024-05-26 09:43:52 +00:00
|
|
|
import { getAllUserChats } from '$lib/apis/chats';
|
2024-03-02 20:38:51 +00:00
|
|
|
|
|
|
|
const i18n = getContext('i18n');
|
2024-03-02 08:33:20 +00:00
|
|
|
|
|
|
|
export let saveHandler: Function;
|
|
|
|
|
2024-05-26 09:43:52 +00:00
|
|
|
const exportAllUserChats = async () => {
|
|
|
|
let blob = new Blob([JSON.stringify(await getAllUserChats(localStorage.token))], {
|
|
|
|
type: 'application/json'
|
|
|
|
});
|
|
|
|
saveAs(blob, `all-chats-export-${Date.now()}.json`);
|
|
|
|
};
|
|
|
|
|
2024-03-02 08:33:20 +00:00
|
|
|
onMount(async () => {
|
|
|
|
// permissions = await getUserPermissions(localStorage.token);
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<form
|
|
|
|
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
|
|
|
on:submit|preventDefault={async () => {
|
|
|
|
saveHandler();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-80">
|
|
|
|
<div>
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" mb-2 text-sm font-medium">{$i18n.t('Database')}</div>
|
2024-03-02 08:33:20 +00:00
|
|
|
|
2024-05-26 10:13:13 +00:00
|
|
|
{#if $config?.enable_admin_export ?? true}
|
2024-05-26 09:43:52 +00:00
|
|
|
<div class=" flex w-full justify-between">
|
|
|
|
<!-- <div class=" self-center text-xs font-medium">{$i18n.t('Allow Chat Deletion')}</div> -->
|
2024-03-02 08:33:20 +00:00
|
|
|
|
2024-04-17 08:33:22 +00:00
|
|
|
<button
|
|
|
|
class=" flex rounded-md py-1.5 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
|
|
|
type="button"
|
|
|
|
on:click={() => {
|
2024-04-22 18:55:46 +00:00
|
|
|
// exportAllUserChats();
|
2024-03-02 08:33:20 +00:00
|
|
|
|
2024-04-27 14:53:31 +00:00
|
|
|
downloadDatabase(localStorage.token).catch((error) => {
|
|
|
|
toast.error(error);
|
|
|
|
});
|
2024-04-22 18:55:46 +00:00
|
|
|
}}
|
2024-04-17 08:33:22 +00:00
|
|
|
>
|
|
|
|
<div class=" self-center mr-3">
|
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
viewBox="0 0 16 16"
|
|
|
|
fill="currentColor"
|
|
|
|
class="w-4 h-4"
|
|
|
|
>
|
|
|
|
<path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
|
|
|
|
<path
|
|
|
|
fill-rule="evenodd"
|
|
|
|
d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM8.75 7.75a.75.75 0 0 0-1.5 0v2.69L6.03 9.22a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l2.5-2.5a.75.75 0 1 0-1.06-1.06l-1.22 1.22V7.75Z"
|
|
|
|
clip-rule="evenodd"
|
|
|
|
/>
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
<div class=" self-center text-sm font-medium">{$i18n.t('Download Database')}</div>
|
|
|
|
</button>
|
2024-05-26 09:43:52 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class=" dark:border-gray-700 my-1" />
|
|
|
|
|
|
|
|
<button
|
|
|
|
class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
|
|
|
on:click={() => {
|
|
|
|
exportAllUserChats();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div class=" self-center mr-3">
|
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
viewBox="0 0 16 16"
|
|
|
|
fill="currentColor"
|
|
|
|
class="w-4 h-4"
|
|
|
|
>
|
|
|
|
<path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
|
|
|
|
<path
|
|
|
|
fill-rule="evenodd"
|
|
|
|
d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM8.75 7.75a.75.75 0 0 0-1.5 0v2.69L6.03 9.22a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l2.5-2.5a.75.75 0 1 0-1.06-1.06l-1.22 1.22V7.75Z"
|
|
|
|
clip-rule="evenodd"
|
|
|
|
/>
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
<div class=" self-center text-sm font-medium">
|
|
|
|
{$i18n.t('Export All Chats (All Users)')}
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
{/if}
|
2024-03-02 08:33:20 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- <div class="flex justify-end pt-3 text-sm font-medium">
|
|
|
|
<button
|
2024-04-28 01:20:43 +00:00
|
|
|
class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
|
2024-03-02 08:33:20 +00:00
|
|
|
type="submit"
|
|
|
|
>
|
|
|
|
Save
|
|
|
|
</button>
|
2024-04-28 01:20:43 +00:00
|
|
|
|
2024-03-02 08:33:20 +00:00
|
|
|
</div> -->
|
|
|
|
</form>
|