refactor: Refactor storage keys into hierarchical structure

This commit is contained in:
zhsama
2026-01-30 23:23:21 +08:00
parent a052c414ac
commit 03ec2f64cd
9 changed files with 52 additions and 35 deletions

View File

@ -272,7 +272,7 @@ const useContextGenerate = ({
const [inputValue, setInputValue] = useState('')
const [isGenerating, { setTrue: setGeneratingTrue, setFalse: setGeneratingFalse }] = useBoolean(false)
const [modelOverride, setModelOverride] = useState<Model | null>(() => {
const stored = localStorage.getItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL)
const stored = localStorage.getItem(STORAGE_KEYS.LOCAL.GENERATOR.AUTO_GEN_MODEL)
if (!stored)
return null
const parsed = JSON.parse(stored) as Model
@ -328,7 +328,7 @@ const useContextGenerate = ({
mode: newValue.mode as ModelModeType,
}
setModelOverride(newModel)
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
localStorage.setItem(STORAGE_KEYS.LOCAL.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
}, [model])
const handleCompletionParamsChange = useCallback((newParams: FormValue) => {
@ -337,7 +337,7 @@ const useContextGenerate = ({
completion_params: newParams as CompletionParams,
}
setModelOverride(newModel)
localStorage.setItem(STORAGE_KEYS.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
localStorage.setItem(STORAGE_KEYS.LOCAL.GENERATOR.AUTO_GEN_MODEL, JSON.stringify(newModel))
}, [model])
const promptMessageCount = promptMessages?.length ?? 0

View File

@ -1,5 +1,5 @@
// Storage key prefix used by useContextGenData
const CONTEXT_GEN_PREFIX = 'context-gen-'
import { STORAGE_KEYS } from '@/config/storage-keys'
export const CONTEXT_GEN_STORAGE_SUFFIX = {
versions: 'versions',
@ -24,7 +24,7 @@ export const buildContextGenStorageKey = (
}
const buildContextGenStorageKeyWithPrefix = (storageKey: string, suffix: ContextGenStorageSuffix): string => {
return `${CONTEXT_GEN_PREFIX}${storageKey}-${suffix}`
return `${STORAGE_KEYS.SESSION.CONTEXT_GENERATE.PREFIX}${storageKey}-${suffix}`
}
export const getContextGenStorageKey = (storageKey: string, suffix: ContextGenStorageSuffix): string => {