30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
export const getConfig = () => {
|
||
// 从localStorage获取配置,如果不存在则使用默认值
|
||
const getFromLocalStorage = (key: string, defaultValue: string) => {
|
||
try {
|
||
return localStorage.getItem(key) || defaultValue;
|
||
} catch (error) {
|
||
console.warn(`Failed to read ${key} from localStorage:`, error);
|
||
return defaultValue;
|
||
}
|
||
};
|
||
|
||
return {
|
||
VOLCENGINE_AUC_APPID: getFromLocalStorage('VOLCENGINE_AUC_APPID', ''),
|
||
VOLCENGINE_AUC_TOKEN: getFromLocalStorage('VOLCENGINE_AUC_TOKEN', ''),
|
||
};
|
||
};
|
||
|
||
export const setConfig = (config: { VOLCENGINE_AUC_APPID?: string; VOLCENGINE_AUC_TOKEN?: string }) => {
|
||
// 将配置保存到localStorage
|
||
try {
|
||
if (config.VOLCENGINE_AUC_APPID !== undefined) {
|
||
localStorage.setItem('VOLCENGINE_AUC_APPID', config.VOLCENGINE_AUC_APPID);
|
||
}
|
||
if (config.VOLCENGINE_AUC_TOKEN !== undefined) {
|
||
localStorage.setItem('VOLCENGINE_AUC_TOKEN', config.VOLCENGINE_AUC_TOKEN);
|
||
}
|
||
} catch (error) {
|
||
console.warn('Failed to save config to localStorage:', error);
|
||
}
|
||
}; |