Enhance: Google Photos integration, refinement of Schedule/Todo lists and API fixes
This commit is contained in:
@@ -45,25 +45,22 @@ router.get("/", async (req, res) => {
|
||||
|
||||
const currentData = currentResponse.data;
|
||||
|
||||
// 3. Process Forecast for Today's Min/Max (Seoul Time: UTC+9)
|
||||
// OpenWeatherMap returns timestamps in UTC.
|
||||
// Seoul is UTC+9.
|
||||
const SeoulOffset = 9 * 60 * 60 * 1000;
|
||||
const nowKST = new Date(Date.now() + SeoulOffset);
|
||||
const todayStr = nowKST.toISOString().split("T")[0]; // YYYY-MM-DD in KST
|
||||
// 3. Process Forecast for Today's Min/Max (Rolling 24-hour window for stability)
|
||||
// We use the first 8 segments (3h * 8 = 24h) to ensure we always have a full
|
||||
// day-night cycle of temperatures, providing a stable daily range.
|
||||
const forecastList = forecastResponse.data.list;
|
||||
if (forecastList && forecastList.length > 0) {
|
||||
const next24h = forecastList.slice(0, 8);
|
||||
|
||||
const todayItems = forecastResponse.data.list.filter((item) => {
|
||||
const itemDateKST = new Date(item.dt * 1000 + SeoulOffset);
|
||||
const itemDateStr = itemDateKST.toISOString().split("T")[0];
|
||||
return itemDateStr === todayStr;
|
||||
});
|
||||
// Calculate min/max from forecast
|
||||
let minTemp = Math.min(...next24h.map((item) => item.main.temp_min));
|
||||
let maxTemp = Math.max(...next24h.map((item) => item.main.temp_max));
|
||||
|
||||
if (todayItems.length > 0) {
|
||||
// Find min and max from the 3-hour segments
|
||||
const minTemp = Math.min(...todayItems.map((item) => item.main.temp_min));
|
||||
const maxTemp = Math.max(...todayItems.map((item) => item.main.temp_max));
|
||||
// Also compare with current temperature to ensure the range covers current state
|
||||
const currentTemp = currentData.main.temp;
|
||||
minTemp = Math.min(minTemp, currentTemp);
|
||||
maxTemp = Math.max(maxTemp, currentTemp);
|
||||
|
||||
// Update the response structure
|
||||
currentData.main.temp_min = minTemp;
|
||||
currentData.main.temp_max = maxTemp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user