mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Restrict weather data access to administrators only
Remove direct weather data access for all users and enforce administrator-only viewing of weather information by implementing role-based access control on the API endpoint. Refactor weather system initialization to use a new auto-configuration module that fetches API keys from environment variables. Replit-Commit-Author: Agent Replit-Commit-Session-Id: d43bd811-9372-45a7-8ac9-4a954c0538e1 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/d43bd811-9372-45a7-8ac9-4a954c0538e1/cp1Ryg6
This commit is contained in:
1 parent
c6b2120f06
commit
62803e7b39
5 files changed
+75
-49
No files matched your search
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Auto-configuration du système météo pour la production
|
||||
* Configure automatiquement les paramètres météo avec la clé API des variables d'environnement
|
||||
*/
|
||||
|
||||
import { storage } from "./storage.js";
|
||||
import { weatherService } from "./weatherService.js";
|
||||
|
||||
export async function initializeWeatherConfig() {
|
||||
try {
|
||||
console.log('🌤️ [AUTO-CONFIG] Initializing weather configuration...');
|
||||
|
||||
// Vérifier si la configuration météo existe déjà
|
||||
const existingSettings = await storage.getWeatherSettings();
|
||||
|
||||
if (existingSettings && existingSettings.isActive) {
|
||||
console.log('✅ [AUTO-CONFIG] Weather settings already configured and active');
|
||||
return;
|
||||
}
|
||||
|
||||
// Récupérer la clé API depuis les variables d'environnement
|
||||
const apiKey = process.env.VISUAL_CROSSING_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
console.log('⚠️ [AUTO-CONFIG] VISUAL_CROSSING_API_KEY not found in environment variables');
|
||||
return;
|
||||
}
|
||||
|
||||
// Configuration par défaut
|
||||
const defaultConfig = {
|
||||
apiKey: apiKey,
|
||||
location: "Nancy, France",
|
||||
isActive: true
|
||||
};
|
||||
|
||||
console.log('🌤️ [AUTO-CONFIG] Testing API connection...');
|
||||
|
||||
// Tester la connexion API avant de sauvegarder
|
||||
const testResult = await weatherService.testApiConnection(defaultConfig.apiKey, defaultConfig.location);
|
||||
|
||||
if (!testResult.success) {
|
||||
console.error('❌ [AUTO-CONFIG] API test failed:', testResult.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ [AUTO-CONFIG] API test successful');
|
||||
|
||||
// Créer ou mettre à jour la configuration
|
||||
if (existingSettings) {
|
||||
// Mettre à jour la configuration existante
|
||||
await storage.updateWeatherSettings(existingSettings.id, defaultConfig);
|
||||
console.log('🔄 [AUTO-CONFIG] Weather settings updated');
|
||||
} else {
|
||||
// Créer une nouvelle configuration
|
||||
await storage.createWeatherSettings(defaultConfig);
|
||||
console.log('🆕 [AUTO-CONFIG] Weather settings created');
|
||||
}
|
||||
|
||||
console.log('✅ [AUTO-CONFIG] Weather system successfully configured');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ [AUTO-CONFIG] Failed to initialize weather config:', error);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user