refac
This commit is contained in:
@@ -49,188 +49,123 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form
|
<div class="flex flex-col h-full justify-between text-sm">
|
||||||
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
<div class="space-y-3 overflow-y-scroll scrollbar-hidden h-full">
|
||||||
on:submit|preventDefault={async () => {
|
<input
|
||||||
saveHandler();
|
id="config-json-input"
|
||||||
}}
|
hidden
|
||||||
>
|
type="file"
|
||||||
<div class=" space-y-3 overflow-y-scroll scrollbar-hidden h-full">
|
accept=".json"
|
||||||
<div>
|
on:change={(e) => {
|
||||||
<div class=" mb-2 text-sm font-medium">{$i18n.t('Database')}</div>
|
const file = e.target.files[0];
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
<input
|
reader.onload = async (e) => {
|
||||||
id="config-json-input"
|
const res = await importConfig(localStorage.token, JSON.parse(e.target.result)).catch(
|
||||||
hidden
|
(error) => {
|
||||||
type="file"
|
toast.error(`${error}`);
|
||||||
accept=".json"
|
|
||||||
on:change={(e) => {
|
|
||||||
const file = e.target.files[0];
|
|
||||||
const reader = new FileReader();
|
|
||||||
|
|
||||||
reader.onload = async (e) => {
|
|
||||||
const res = await importConfig(localStorage.token, JSON.parse(e.target.result)).catch(
|
|
||||||
(error) => {
|
|
||||||
toast.error(`${error}`);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
toast.success($i18n.t('Config imported successfully'));
|
|
||||||
}
|
}
|
||||||
e.target.value = null;
|
);
|
||||||
};
|
|
||||||
|
|
||||||
reader.readAsText(file);
|
if (res) {
|
||||||
}}
|
toast.success($i18n.t('Config imported successfully'));
|
||||||
/>
|
}
|
||||||
|
e.target.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
<button
|
reader.readAsText(file);
|
||||||
type="button"
|
}}
|
||||||
class=" flex rounded-md py-2 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
/>
|
||||||
on:click={async () => {
|
|
||||||
document.getElementById('config-json-input').click();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<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('Import Config from JSON File')}
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
<div>
|
||||||
type="button"
|
<div class="mb-1 text-sm font-medium">{$i18n.t('Config')}</div>
|
||||||
class=" flex rounded-md py-2 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
|
||||||
on:click={async () => {
|
|
||||||
const config = await exportConfig(localStorage.token);
|
|
||||||
const blob = new Blob([JSON.stringify(config)], {
|
|
||||||
type: 'application/json'
|
|
||||||
});
|
|
||||||
saveAs(blob, `config-${Date.now()}.json`);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<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 Config to JSON File')}
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<hr class="border-gray-50 dark:border-gray-850/30 my-1" />
|
|
||||||
|
|
||||||
{#if $config?.features.enable_admin_export ?? true}
|
|
||||||
<div class=" flex w-full justify-between">
|
|
||||||
<!-- <div class=" self-center text-xs font-medium">{$i18n.t('Allow Chat Deletion')}</div> -->
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="py-0.5 flex w-full justify-between">
|
||||||
|
<div class="self-center text-xs">{$i18n.t('Import Config')}</div>
|
||||||
<button
|
<button
|
||||||
class=" flex rounded-md py-1.5 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||||
type="button"
|
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
// exportAllUserChats();
|
document.getElementById('config-json-input').click();
|
||||||
|
|
||||||
downloadDatabase(localStorage.token).catch((error) => {
|
|
||||||
toast.error(`${error}`);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
|
type="button"
|
||||||
>
|
>
|
||||||
<div class=" self-center mr-3">
|
<span class="self-center">{$i18n.t('Import')}</span>
|
||||||
<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>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button
|
<div>
|
||||||
class=" flex rounded-md py-2 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
<div class="py-0.5 flex w-full justify-between">
|
||||||
on:click={() => {
|
<div class="self-center text-xs">{$i18n.t('Export Config')}</div>
|
||||||
exportAllUserChats();
|
<button
|
||||||
}}
|
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||||
>
|
on:click={async () => {
|
||||||
<div class=" self-center mr-3">
|
const config = await exportConfig(localStorage.token);
|
||||||
<svg
|
const blob = new Blob([JSON.stringify(config)], {
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
type: 'application/json'
|
||||||
viewBox="0 0 16 16"
|
});
|
||||||
fill="currentColor"
|
saveAs(blob, `config-${Date.now()}.json`);
|
||||||
class="w-4 h-4"
|
}}
|
||||||
>
|
type="button"
|
||||||
<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
|
<span class="self-center">{$i18n.t('Export')}</span>
|
||||||
fill-rule="evenodd"
|
</button>
|
||||||
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"
|
</div>
|
||||||
clip-rule="evenodd"
|
</div>
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div class=" self-center text-sm font-medium">
|
|
||||||
{$i18n.t('Export All Chats (All Users)')}
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
|
||||||
class=" flex rounded-md py-2 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
|
||||||
on:click={() => {
|
|
||||||
exportUsers();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<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 Users')}
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if $config?.features.enable_admin_export ?? true}
|
||||||
|
<div>
|
||||||
|
<div class="mb-1 text-sm font-medium">{$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>
|
||||||
</form>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user