Skip to content

Commit 5134e5e

Browse files
committed
refac
1 parent caadfde commit 5134e5e

2 files changed

Lines changed: 33 additions & 45 deletions

File tree

backend/open_webui/routers/knowledge.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,18 +2126,13 @@ async def export_knowledge_by_id(id: str, user=Depends(get_admin_user), db: Asyn
21262126
zip_buffer.seek(0)
21272127

21282128
# Sanitize knowledge name for filename
2129-
# ASCII-safe fallback for the basic filename parameter (latin-1 safe)
2130-
safe_name = ''.join(c if c.isascii() and (c.isalnum() or c in ' -_') else '_' for c in knowledge.name)
2129+
safe_name = ''.join(c if c.isalnum() or c in ' -_' else '_' for c in knowledge.name)
21312130
zip_filename = f'{safe_name}.zip'
21322131

2133-
# Use RFC 5987 filename* for non-ASCII names so the browser gets the real name
2134-
quoted_name = quote(f'{knowledge.name}.zip')
2135-
content_disposition = f'attachment; filename="{zip_filename}"; filename*=UTF-8\'\'{quoted_name}'
2136-
21372132
return StreamingResponse(
21382133
zip_buffer,
21392134
media_type='application/zip',
2140-
headers={'Content-Disposition': content_disposition},
2135+
headers={'Content-Disposition': f"attachment; filename*=UTF-8''{quote(zip_filename, safe='')}"},
21412136
)
21422137

21432138

src/lib/components/admin/Settings/Audio.svelte

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
import Spinner from '$lib/components/common/Spinner.svelte';
1616
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
17+
import TTSVoiceInput from '$lib/components/workspace/Models/TTSVoiceInput.svelte';
1718
1819
import { TTS_RESPONSE_SPLIT } from '$lib/types';
1920
@@ -58,8 +59,18 @@
5859
5960
let STT_WHISPER_MODEL_LOADING = false;
6061
62+
type Voice = {
63+
id: string;
64+
name?: string;
65+
description?: string;
66+
meta?: {
67+
description?: string;
68+
};
69+
};
70+
6171
// eslint-disable-next-line no-undef
6272
let voices: SpeechSynthesisVoice[] = [];
73+
let providerVoices: Voice[] = [];
6374
let models: Awaited<ReturnType<typeof _getModels>>['models'] = [];
6475
6576
const getModels = async () => {
@@ -82,6 +93,8 @@
8293
8394
const getVoices = async () => {
8495
if (TTS_ENGINE === '') {
96+
providerVoices = [];
97+
8598
const getVoicesLoop = setInterval(() => {
8699
voices = speechSynthesis.getVoices();
87100
@@ -92,14 +105,18 @@
92105
}
93106
}, 100);
94107
} else {
108+
voices = [];
109+
95110
const res = await _getVoices(localStorage.token).catch((e) => {
96111
toast.error(`${e}`);
97112
});
98113
99114
if (res) {
100115
console.log(res);
101-
voices = res.voices;
102-
voices.sort((a, b) => a.name.localeCompare(b.name, $i18n.resolvedLanguage));
116+
providerVoices = res.voices ?? [];
117+
providerVoices.sort((a, b) =>
118+
(a.name ?? a.id).localeCompare(b.name ?? b.id, $i18n.resolvedLanguage)
119+
);
103120
}
104121
}
105122
};
@@ -679,18 +696,12 @@
679696
<div class=" mb-1.5 text-xs font-medium">{$i18n.t('TTS Voice')}</div>
680697
<div class="flex w-full">
681698
<div class="flex-1">
682-
<input
683-
list="voice-list"
684-
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
699+
<TTSVoiceInput
685700
bind:value={TTS_VOICE}
701+
voices={providerVoices}
686702
placeholder={$i18n.t('Select a voice')}
703+
className="w-full rounded-lg py-2 px-4 bg-gray-50 dark:text-gray-300 dark:bg-gray-850"
687704
/>
688-
689-
<datalist id="voice-list">
690-
{#each voices as voice}
691-
<option value={voice.id}>{voice.name}</option>
692-
{/each}
693-
</datalist>
694705
</div>
695706
</div>
696707
</div>
@@ -736,18 +747,12 @@
736747
<div class=" mb-1.5 text-xs font-medium">{$i18n.t('TTS Voice')}</div>
737748
<div class="flex w-full">
738749
<div class="flex-1">
739-
<input
740-
list="voice-list"
741-
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
750+
<TTSVoiceInput
742751
bind:value={TTS_VOICE}
752+
voices={providerVoices}
743753
placeholder={$i18n.t('Select a voice')}
754+
className="w-full rounded-lg py-2 px-4 bg-gray-50 dark:text-gray-300 dark:bg-gray-850"
744755
/>
745-
746-
<datalist id="voice-list">
747-
{#each voices as voice}
748-
<option value={voice.id}>{voice.name}</option>
749-
{/each}
750-
</datalist>
751756
</div>
752757
</div>
753758
</div>
@@ -777,18 +782,12 @@
777782
<div class=" mb-1.5 text-xs font-medium">{$i18n.t('TTS Voice')}</div>
778783
<div class="flex w-full">
779784
<div class="flex-1">
780-
<input
781-
list="voice-list"
782-
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
785+
<TTSVoiceInput
783786
bind:value={TTS_VOICE}
787+
voices={providerVoices}
784788
placeholder={$i18n.t('Select a voice')}
789+
className="w-full rounded-lg py-2 px-4 bg-gray-50 dark:text-gray-300 dark:bg-gray-850"
785790
/>
786-
787-
<datalist id="voice-list">
788-
{#each voices as voice}
789-
<option value={voice.id}>{voice.name}</option>
790-
{/each}
791-
</datalist>
792791
</div>
793792
</div>
794793
</div>
@@ -820,18 +819,12 @@
820819
<div class=" mb-1.5 text-xs font-medium">{$i18n.t('TTS Voice')}</div>
821820
<div class="flex w-full">
822821
<div class="flex-1">
823-
<input
824-
list="voice-list"
825-
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
822+
<TTSVoiceInput
826823
bind:value={TTS_VOICE}
824+
voices={providerVoices}
827825
placeholder={$i18n.t('Select a voice')}
826+
className="w-full rounded-lg py-2 px-4 bg-gray-50 dark:text-gray-300 dark:bg-gray-850"
828827
/>
829-
830-
<datalist id="voice-list">
831-
{#each voices as voice}
832-
<option value={voice.id}>{voice.name}</option>
833-
{/each}
834-
</datalist>
835828
</div>
836829
</div>
837830
</div>

0 commit comments

Comments
 (0)