Files
noteflow/src/services/SettingsService.ts
T
Claude e480d50bea Feature: Ajout du support d'API Key pour Google Calendar
Ajout d'une troisième méthode d'authentification pour Google Calendar :
- OAuth 2.0 (existant)
- Service Account (existant)
- API Key (nouveau)

Modifications :
- Interface d'administration avec sélection API Key
- Champs pour configurer la clé API et l'ID du calendrier
- Backend mis à jour pour gérer l'authentification par API Key
- Routes calendar adaptées pour supporter le nouveau type
- Affichage du statut de connexion mis à jour

L'utilisateur peut maintenant :
1. Sélectionner "API externe" dans les paramètres Google Calendar
2. Entrer sa clé API Google Calendar
3. Spécifier l'ID du calendrier (ou "primary")
4. Synchroniser directement avec Google Calendar
2025-11-12 13:22:34 +00:00

62 lines
1.6 KiB
TypeScript

import axios from 'axios';
export interface Settings {
openrouter_api_key?: string;
ai_model?: string;
rss_refresh_interval?: number;
theme?: 'light' | 'dark' | 'auto';
google_client_id?: string;
google_client_secret?: string;
google_auth_type?: 'oauth2' | 'service_account' | 'api_externe';
google_service_account_key?: string;
google_calendar_email?: string;
google_calendar_api_key?: string;
google_calendar_id?: string;
}
class SettingsService {
private baseURL = '/api/settings';
private getAuthHeader() {
const token = localStorage.getItem('token');
return {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
};
}
async getSettings(): Promise<Settings> {
try {
const response = await axios.get(this.baseURL, this.getAuthHeader());
return response.data;
} catch (error) {
console.error('Error fetching settings:', error);
throw error;
}
}
async updateSettings(settings: Settings): Promise<boolean> {
try {
await axios.put(this.baseURL, settings, this.getAuthHeader());
return true;
} catch (error) {
console.error('Error updating settings:', error);
throw error;
}
}
async testOpenRouterConnection(): Promise<boolean> {
try {
const response = await axios.post(`${this.baseURL}/test-openrouter`, {}, this.getAuthHeader());
return response.data.success;
} catch (error) {
console.error('Error testing OpenRouter connection:', error);
throw error;
}
}
}
export default new SettingsService();