fetch refactoring
This commit is contained in:
parent
9a5431cffa
commit
0122e9b456
4 changed files with 27 additions and 27 deletions
|
@ -1,11 +1,11 @@
|
|||
const EleventyFetch = require('@11ty/eleventy-fetch')
|
||||
const fetch = require('node-fetch')
|
||||
const { AssetCache } = require('@11ty/eleventy-fetch')
|
||||
|
||||
module.exports = async function () {
|
||||
const url = 'https://api.omg.lol/address/cory/statuses/'
|
||||
const res = EleventyFetch(url, {
|
||||
duration: '1d',
|
||||
type: 'json',
|
||||
})
|
||||
const status = await res
|
||||
const asset = new AssetCache('status_data')
|
||||
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
|
||||
const status = await fetch(url).then((res) => res.json())
|
||||
await asset.save(status, 'json')
|
||||
return status.response.statuses[0]
|
||||
}
|
||||
|
|
Reference in a new issue