generated from kevisual/vite-react-template
add defult conifg
This commit is contained in:
@@ -10,6 +10,15 @@ type ConfigState = {
|
|||||||
|
|
||||||
const STORAGE_KEY = 'cnb-config';
|
const STORAGE_KEY = 'cnb-config';
|
||||||
|
|
||||||
|
const DEFAULT_CONFIG = {
|
||||||
|
CNB_API_KEY: '',
|
||||||
|
CNB_COOKIE: '',
|
||||||
|
CNB_CORS_URL: 'https://cors.kevisual.cn',
|
||||||
|
ENABLE_CORS: true,
|
||||||
|
AI_BASE_URL: 'https://api.cnb.cool/kevisual/cnb-ai/-/ai/',
|
||||||
|
AI_MODEL: 'CNB-Models',
|
||||||
|
AI_API_KEY: ''
|
||||||
|
}
|
||||||
const loadInitialConfig = (): Config => {
|
const loadInitialConfig = (): Config => {
|
||||||
try {
|
try {
|
||||||
const stored = localStorage.getItem(STORAGE_KEY);
|
const stored = localStorage.getItem(STORAGE_KEY);
|
||||||
@@ -19,15 +28,7 @@ const loadInitialConfig = (): Config => {
|
|||||||
} catch {
|
} catch {
|
||||||
// Ignore parse errors
|
// Ignore parse errors
|
||||||
}
|
}
|
||||||
return {
|
return DEFAULT_CONFIG;
|
||||||
CNB_API_KEY: '',
|
|
||||||
CNB_COOKIE: '',
|
|
||||||
CNB_CORS_URL: 'https://cors.kevisual.cn',
|
|
||||||
ENABLE_CORS: true,
|
|
||||||
AI_BASE_URL: '',
|
|
||||||
AI_MODEL: '',
|
|
||||||
AI_API_KEY: ''
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useConfigStore = create<ConfigState>()(
|
export const useConfigStore = create<ConfigState>()(
|
||||||
@@ -40,15 +41,7 @@ export const useConfigStore = create<ConfigState>()(
|
|||||||
})),
|
})),
|
||||||
resetConfig: () =>
|
resetConfig: () =>
|
||||||
set({
|
set({
|
||||||
config: {
|
config: DEFAULT_CONFIG,
|
||||||
CNB_API_KEY: '',
|
|
||||||
CNB_COOKIE: '',
|
|
||||||
CNB_CORS_URL: 'https://cors.kevisual.cn',
|
|
||||||
ENABLE_CORS: true,
|
|
||||||
AI_BASE_URL: 'https://api.cnb.cool/kevisual/cnb-ai/-/ai/',
|
|
||||||
AI_MODEL: 'CNB-Models',
|
|
||||||
AI_API_KEY: ''
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user