open-webui/src/lib/components/admin/Settings/General.svelte

147 lines
4.4 KiB
Svelte
Raw Normal View History

2024-02-14 09:17:43 +00:00
<script lang="ts">
2024-08-19 13:16:49 +00:00
import { getBackendConfig, getWebhookUrl, updateWebhookUrl } from '$lib/apis';
import { getAdminConfig, updateAdminConfig } from '$lib/apis/auths';
import Switch from '$lib/components/common/Switch.svelte';
2024-08-19 13:16:49 +00:00
import { config } from '$lib/stores';
import { onMount, getContext } from 'svelte';
2024-08-19 13:16:49 +00:00
import { toast } from 'svelte-sonner';
const i18n = getContext('i18n');
2024-02-14 09:17:43 +00:00
export let saveHandler: Function;
let adminConfig = null;
2024-03-21 01:35:54 +00:00
let webhookUrl = '';
const updateHandler = async () => {
2024-03-21 01:35:54 +00:00
webhookUrl = await updateWebhookUrl(localStorage.token, webhookUrl);
const res = await updateAdminConfig(localStorage.token, adminConfig);
2024-03-21 01:35:54 +00:00
if (res) {
2024-08-19 13:16:49 +00:00
saveHandler();
} else {
toast.error(i18n.t('Failed to update settings'));
}
};
2024-02-14 09:17:43 +00:00
onMount(async () => {
await Promise.all([
(async () => {
adminConfig = await getAdminConfig(localStorage.token);
})(),
(async () => {
webhookUrl = await getWebhookUrl(localStorage.token);
})()
]);
2024-02-14 09:17:43 +00:00
});
</script>
<form
class="flex flex-col h-full justify-between space-y-3 text-sm"
2024-08-19 13:16:49 +00:00
on:submit|preventDefault={async () => {
updateHandler();
2024-02-14 09:17:43 +00:00
}}
>
2024-06-09 09:41:52 +00:00
<div class=" space-y-3 overflow-y-scroll scrollbar-hidden h-full">
{#if adminConfig !== null}
<div>
<div class=" mb-3 text-sm font-medium">{$i18n.t('General Settings')}</div>
<div class=" flex w-full justify-between pr-2">
<div class=" self-center text-xs font-medium">{$i18n.t('Enable New Sign Ups')}</div>
2024-02-14 09:17:43 +00:00
<Switch bind:state={adminConfig.ENABLE_SIGNUP} />
2024-02-14 09:17:43 +00:00
</div>
2024-02-20 04:44:00 +00:00
<div class=" my-3 flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('Default User Role')}</div>
<div class="flex items-center relative">
<select
class="dark:bg-gray-900 w-fit pr-8 rounded px-2 text-xs bg-transparent outline-none text-right"
bind:value={adminConfig.DEFAULT_USER_ROLE}
placeholder="Select a role"
>
<option value="pending">{$i18n.t('pending')}</option>
<option value="user">{$i18n.t('user')}</option>
<option value="admin">{$i18n.t('admin')}</option>
</select>
</div>
</div>
<hr class=" dark:border-gray-850 my-2" />
2024-03-21 01:35:54 +00:00
<div class="my-3 flex w-full items-center justify-between pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Show Admin Details in Account Pending Overlay')}
</div>
2024-03-21 01:35:54 +00:00
<Switch bind:state={adminConfig.SHOW_ADMIN_DETAILS} />
2024-03-21 01:35:54 +00:00
</div>
<div class="my-3 flex w-full items-center justify-between pr-2">
<div class=" self-center text-xs font-medium">{$i18n.t('Enable Community Sharing')}</div>
2024-02-20 04:44:00 +00:00
<Switch bind:state={adminConfig.ENABLE_COMMUNITY_SHARING} />
2024-02-20 04:44:00 +00:00
</div>
2024-08-19 13:16:49 +00:00
<div class="my-3 flex w-full items-center justify-between pr-2">
<div class=" self-center text-xs font-medium">{$i18n.t('Enable Message Rating')}</div>
<Switch bind:state={adminConfig.ENABLE_MESSAGE_RATING} />
</div>
<hr class=" dark:border-gray-850 my-2" />
<div class=" w-full justify-between">
<div class="flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('JWT Expiration')}</div>
</div>
<div class="flex mt-2 space-x-2">
<input
2024-07-09 03:10:00 +00:00
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
type="text"
placeholder={`e.g.) "30m","1h", "10d". `}
bind:value={adminConfig.JWT_EXPIRES_IN}
/>
</div>
<div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
{$i18n.t('Valid time units:')}
<span class=" text-gray-300 font-medium"
>{$i18n.t("'s', 'm', 'h', 'd', 'w' or '-1' for no expiration.")}</span
>
</div>
2024-02-20 04:44:00 +00:00
</div>
<hr class=" dark:border-gray-850 my-2" />
<div class=" w-full justify-between">
<div class="flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('Webhook URL')}</div>
</div>
<div class="flex mt-2 space-x-2">
<input
2024-07-09 03:10:00 +00:00
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
type="text"
placeholder={`https://example.com/webhook`}
bind:value={webhookUrl}
/>
</div>
2024-02-20 04:44:00 +00:00
</div>
</div>
{/if}
2024-02-14 09:17:43 +00:00
</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-02-14 09:17:43 +00:00
type="submit"
>
2024-03-04 08:53:56 +00:00
{$i18n.t('Save')}
2024-02-14 09:17:43 +00:00
</button>
</div>
</form>