Icon caching
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user