Icon caching

This commit is contained in:
2026-06-26 20:52:54 -04:00
parent aeffa30417
commit 73f1453daf
15 changed files with 29 additions and 60 deletions

View File

@@ -33,17 +33,6 @@ const OWM_ICONS = {
95: '11d', 96: '11d', 99: '11d',
}
async function ensureIcon(code) {
const owmCode = OWM_ICONS[code] || '01d'
const filename = `${owmCode}.png`
const filepath = resolve(ICON_DIR, filename)
if (!existsSync(filepath)) {
const res = await fetch(`https://openweathermap.org/img/wn/${owmCode}@2x.png`)
await pipeline(res.body, createWriteStream(filepath))
}
return `/icons/${filename}`
}
async function cachedFetch(key, url) {
const now = Date.now()
if (CACHE[key] && now - CACHE[key].ts < CACHE_MS) return CACHE[key].data