feat: save user settings to db
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
import type { Writable } from 'svelte/store';
|
||||
import type { i18n as i18nType } from 'i18next';
|
||||
import Banner from '../common/Banner.svelte';
|
||||
import { getUserSettings } from '$lib/apis/users';
|
||||
|
||||
const i18n: Writable<i18nType> = getContext('i18n');
|
||||
|
||||
@@ -154,10 +155,13 @@
|
||||
$models.map((m) => m.id).includes(modelId) ? modelId : ''
|
||||
);
|
||||
|
||||
let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
|
||||
settings.set({
|
||||
..._settings
|
||||
});
|
||||
const userSettings = await getUserSettings(localStorage.token);
|
||||
|
||||
if (userSettings) {
|
||||
settings.set(userSettings.ui);
|
||||
} else {
|
||||
settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
|
||||
}
|
||||
|
||||
const chatInput = document.getElementById('chat-textarea');
|
||||
setTimeout(() => chatInput?.focus(), 0);
|
||||
@@ -187,11 +191,18 @@
|
||||
: convertMessagesToHistory(chatContent.messages);
|
||||
title = chatContent.title;
|
||||
|
||||
let _settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
|
||||
const userSettings = await getUserSettings(localStorage.token);
|
||||
|
||||
if (userSettings) {
|
||||
await settings.set(userSettings.ui);
|
||||
} else {
|
||||
await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
|
||||
}
|
||||
|
||||
await settings.set({
|
||||
..._settings,
|
||||
system: chatContent.system ?? _settings.system,
|
||||
params: chatContent.options ?? _settings.params
|
||||
...$settings,
|
||||
system: chatContent.system ?? $settings.system,
|
||||
params: chatContent.options ?? $settings.params
|
||||
});
|
||||
autoScroll = true;
|
||||
await tick();
|
||||
|
||||
Reference in New Issue
Block a user