refac: audio settings

This commit is contained in:
Timothy J. Baek 2024-04-20 19:01:46 -05:00
parent a5f8e87f3f
commit d6a0805966

View file

@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import { getAudioConfig, updateAudioConfig } from '$lib/apis/audio'; import { getAudioConfig, updateAudioConfig } from '$lib/apis/audio';
import { user } from '$lib/stores';
import { createEventDispatcher, onMount, getContext } from 'svelte'; import { createEventDispatcher, onMount, getContext } from 'svelte';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
@ -102,11 +103,13 @@
getWebAPIVoices(); getWebAPIVoices();
} }
const res = await getAudioConfig(localStorage.token); if ($user.role === 'admin') {
const res = await getAudioConfig(localStorage.token);
if (res) { if (res) {
OpenAIUrl = res.OPENAI_API_BASE_URL; OpenAIUrl = res.OPENAI_API_BASE_URL;
OpenAIKey = res.OPENAI_API_KEY; OpenAIKey = res.OPENAI_API_KEY;
}
} }
}); });
</script> </script>
@ -114,7 +117,9 @@
<form <form
class="flex flex-col h-full justify-between space-y-3 text-sm" class="flex flex-col h-full justify-between space-y-3 text-sm"
on:submit|preventDefault={async () => { on:submit|preventDefault={async () => {
await updateConfigHandler(); if ($user.role === 'admin') {
await updateConfigHandler();
}
saveSettings({ saveSettings({
audio: { audio: {
STTEngine: STTEngine !== '' ? STTEngine : undefined, STTEngine: STTEngine !== '' ? STTEngine : undefined,
@ -220,22 +225,24 @@
</div> </div>
</div> </div>
{#if TTSEngine === 'openai'} {#if $user.role === 'admin'}
<div class="mt-1 flex gap-2 mb-1"> {#if TTSEngine === 'openai'}
<input <div class="mt-1 flex gap-2 mb-1">
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none" <input
placeholder={$i18n.t('API Base URL')} class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
bind:value={OpenAIUrl} placeholder={$i18n.t('API Base URL')}
required bind:value={OpenAIUrl}
/> required
/>
<input <input
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none" class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
placeholder={$i18n.t('API Key')} placeholder={$i18n.t('API Key')}
bind:value={OpenAIKey} bind:value={OpenAIKey}
required required
/> />
</div> </div>
{/if}
{/if} {/if}
<div class=" py-0.5 flex w-full justify-between"> <div class=" py-0.5 flex w-full justify-between">
@ -265,7 +272,7 @@
<div class="flex w-full"> <div class="flex w-full">
<div class="flex-1"> <div class="flex-1">
<select <select
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none" class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
bind:value={speaker} bind:value={speaker}
placeholder="Select a voice" placeholder="Select a voice"
> >