Initial commit MKD fixes
This commit is contained in:
77
services/settingsService.ts
Executable file
77
services/settingsService.ts
Executable file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Сервис для работы с настройками интеграций
|
||||
* Хранит настройки в localStorage
|
||||
*/
|
||||
|
||||
export interface DomaAISettings {
|
||||
apiUrl: string;
|
||||
/**
|
||||
* Токен доступа к Doma AI (предпочтительный способ авторизации)
|
||||
*/
|
||||
token?: string;
|
||||
/**
|
||||
* Резервные поля для авторизации по логину/паролю (fallback)
|
||||
*/
|
||||
email?: string;
|
||||
phone?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
export interface IntegrationSettings {
|
||||
domaAI: DomaAISettings;
|
||||
}
|
||||
|
||||
const SETTINGS_KEY = 'mkd_integration_settings';
|
||||
|
||||
export const settingsService = {
|
||||
/**
|
||||
* Получить настройки интеграций
|
||||
*/
|
||||
getIntegrationSettings(): IntegrationSettings | null {
|
||||
try {
|
||||
const stored = localStorage.getItem(SETTINGS_KEY);
|
||||
if (stored) {
|
||||
return JSON.parse(stored);
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
console.error('[settingsService] Ошибка при чтении настроек:', e);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Сохранить настройки интеграций
|
||||
*/
|
||||
saveIntegrationSettings(settings: IntegrationSettings): void {
|
||||
try {
|
||||
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
|
||||
} catch (e) {
|
||||
console.error('[settingsService] Ошибка при сохранении настроек:', e);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Получить настройки Дома.АИ
|
||||
*/
|
||||
getDomaAISettings(): DomaAISettings | null {
|
||||
const settings = this.getIntegrationSettings();
|
||||
return settings?.domaAI || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Сохранить настройки Дома.АИ
|
||||
*/
|
||||
saveDomaAISettings(domaAISettings: DomaAISettings): void {
|
||||
const currentSettings = this.getIntegrationSettings() || { domaAI: domaAISettings };
|
||||
currentSettings.domaAI = domaAISettings;
|
||||
this.saveIntegrationSettings(currentSettings);
|
||||
},
|
||||
|
||||
/**
|
||||
* Очистить настройки интеграций
|
||||
*/
|
||||
clearIntegrationSettings(): void {
|
||||
localStorage.removeItem(SETTINGS_KEY);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user