mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-14 18:59:18 +02:00
Make weather display operational with correct API usage
Fixes 401 error for historical weather data by correcting the API URL syntax from `forecastBasisDate` to `/timeline/location/date`. Updates data formatting for temperature and conditions, ensures weather is visible to all users, and improves production logging for easier debugging. 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/xi5G4qi
This commit is contained in:
1 parent
62803e7b39
commit
d635bfb7c0
4 files changed
+40
-5
No files matched your search
+16
-1
@@ -2886,17 +2886,32 @@ RÉSUMÉ DU SCAN
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
// Toujours retourner une réponse même si seule l'année actuelle est disponible
|
||||
const response = {
|
||||
currentYear: currentYearData ? {
|
||||
...currentYearData,
|
||||
maxTemperature: parseFloat(currentYearData.tempMax),
|
||||
minTemperature: parseFloat(currentYearData.tempMin),
|
||||
condition: currentYearData.conditions,
|
||||
icon: weatherService.getWeatherIcon(currentYearData.icon)
|
||||
} : null,
|
||||
previousYear: previousYearData ? {
|
||||
...previousYearData,
|
||||
maxTemperature: parseFloat(previousYearData.tempMax),
|
||||
minTemperature: parseFloat(previousYearData.tempMin),
|
||||
condition: previousYearData.conditions,
|
||||
icon: weatherService.getWeatherIcon(previousYearData.icon)
|
||||
} : null,
|
||||
location: settings.location
|
||||
};
|
||||
|
||||
console.log('🌤️ [RESPONSE] Weather data prepared:', {
|
||||
hasCurrentYear: !!response.currentYear,
|
||||
hasPreviousYear: !!response.previousYear,
|
||||
location: response.location
|
||||
});
|
||||
|
||||
res.json(response);
|
||||
} catch (error) {
|
||||
console.error("Error fetching weather data:", error);
|
||||
res.status(500).json({ message: "Failed to fetch weather data" });
|
||||
|
||||
@@ -44,18 +44,27 @@ export class WeatherService {
|
||||
*/
|
||||
async fetchPreviousYearWeather(settings: WeatherSettings, targetDate: string): Promise<WeatherApiResponse | null> {
|
||||
try {
|
||||
const url = `${this.baseUrl}/${encodeURIComponent(settings.location)}?unitGroup=metric&include=days&key=${settings.apiKey}&contentType=json&forecastBasisDate=${targetDate}`;
|
||||
// Pour les données historiques, Visual Crossing utilise la syntaxe: /timeline/location/date
|
||||
const url = `${this.baseUrl}/${encodeURIComponent(settings.location)}/${targetDate}?unitGroup=metric&include=days&key=${settings.apiKey}&contentType=json`;
|
||||
|
||||
console.log(`🌤️ [FETCH-HISTORY] Requesting: ${settings.location} for ${targetDate}`);
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
console.error(`Weather API error for previous year: ${response.status} ${response.statusText}`);
|
||||
console.error(`🌤️ [ERROR] Weather API error for previous year: ${response.status} ${response.statusText}`);
|
||||
|
||||
// Pour les données historiques, certains comptes peuvent ne pas avoir accès
|
||||
if (response.status === 401) {
|
||||
console.warn(`⚠️ [WARNING] Historical data access may not be available with current API key`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log(`✅ [FETCH-HISTORY] Successfully retrieved data for ${targetDate}`);
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la météo de l'année précédente:", error);
|
||||
console.error("🌤️ [ERROR] Erreur lors de la récupération de la météo de l'année précédente:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user