filter settings on URL import/export
This commit is contained in:
parent
7fd4ed003c
commit
e991dfd9b7
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { applyProfile, getDefaultProfileKey, getProfile, getProfileSelect, newNameForProfile, setSystemPrompt } from './Profiles.svelte'
|
import { applyProfile, getDefaultProfileKey, getProfile, getProfileSelect, newNameForProfile, setSystemPrompt } from './Profiles.svelte'
|
||||||
import { getChatDefaults, getChatSettingList, getChatSettingObjectByKey, getExcludeFromProfile } from './Settings.svelte'
|
import { getChatDefaults, getChatSettingList, getChatSettingObjectByKey, getExcludeFromProfile, hasChatSetting } from './Settings.svelte'
|
||||||
import {
|
import {
|
||||||
saveChatStore,
|
saveChatStore,
|
||||||
chatsStorage,
|
chatsStorage,
|
||||||
|
@ -102,7 +102,7 @@
|
||||||
// location.protocol + '//' + location.host + location.pathname
|
// location.protocol + '//' + location.host + location.pathname
|
||||||
const uri = '#/chat/new?petals=true&' + Object.entries(chatSettings).reduce((a, [k, v]) => {
|
const uri = '#/chat/new?petals=true&' + Object.entries(chatSettings).reduce((a, [k, v]) => {
|
||||||
const t = typeof v
|
const t = typeof v
|
||||||
if (t === 'boolean' || t === 'string' || t === 'number') {
|
if (hasChatSetting(k) && (t === 'boolean' || t === 'string' || t === 'number')) {
|
||||||
a.push(encodeURI(k) + '=' + encodeURI(v as any))
|
a.push(encodeURI(k) + '=' + encodeURI(v as any))
|
||||||
}
|
}
|
||||||
return a
|
return a
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
import { addChat, setChatSettingValueByKey } from './Storage.svelte'
|
import { addChat, setChatSettingValueByKey } from './Storage.svelte'
|
||||||
import { replace } from 'svelte-spa-router'
|
import { replace } from 'svelte-spa-router'
|
||||||
import { getProfile, restartProfile } from './Profiles.svelte'
|
import { getProfile, restartProfile } from './Profiles.svelte'
|
||||||
import { getChatDefaults } from './Settings.svelte'
|
import { getChatDefaults, hasChatSetting } from './Settings.svelte'
|
||||||
|
|
||||||
// Create the new chat instance then redirect to it
|
// Create the new chat instance then redirect to it
|
||||||
|
|
||||||
const urlParams: URLSearchParams = new URLSearchParams($querystring)
|
const urlParams: URLSearchParams = new URLSearchParams($querystring)
|
||||||
const chatId = urlParams.has('p') ? addChat(getProfile(urlParams.get('p') || '')) : addChat()
|
const chatId = urlParams.has('p') ? addChat(getProfile(urlParams.get('p') || '')) : addChat()
|
||||||
Object.keys(getChatDefaults()).forEach(k => {
|
Object.keys(getChatDefaults()).forEach(k => {
|
||||||
if (urlParams.has(k)) {
|
if (urlParams.has(k) && hasChatSetting(k as any)) {
|
||||||
setChatSettingValueByKey(chatId, k as any, urlParams.get(k))
|
setChatSettingValueByKey(chatId, k as any, urlParams.get(k))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,6 +36,10 @@ export const getRequestSettingList = (): ChatSetting[] => {
|
||||||
return chatSettingsList.filter(s => s.key in gptDefaults)
|
return chatSettingsList.filter(s => s.key in gptDefaults)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const hasChatSetting = (key: keyof ChatSettings): boolean => {
|
||||||
|
return !!chatSettingLookup[key]
|
||||||
|
}
|
||||||
|
|
||||||
export const getChatSettingObjectByKey = (key: keyof ChatSettings): ChatSetting => {
|
export const getChatSettingObjectByKey = (key: keyof ChatSettings): ChatSetting => {
|
||||||
const result = chatSettingLookup[key]
|
const result = chatSettingLookup[key]
|
||||||
if (!result) console.error(`Chat Setting "${key}" not defined in Settings array.`)
|
if (!result) console.error(`Chat Setting "${key}" not defined in Settings array.`)
|
||||||
|
|
Loading…
Reference in New Issue