Revert "fetch refactoring"

This reverts commit 0122e9b456.
This commit is contained in:
Cory Dransfeldt 2023-03-15 04:49:30 -07:00
parent e7421c5803
commit e4ad42cd7f
No known key found for this signature in database
4 changed files with 27 additions and 27 deletions

View file

@ -1,12 +1,12 @@
const fetch = require('node-fetch') const EleventyFetch = require('@11ty/eleventy-fetch')
const { AssetCache } = require('@11ty/eleventy-fetch')
module.exports = async function () { module.exports = async function () {
const url = 'https://utils.coryd.dev/api/now?endpoints=artists,albums,books,movies,tv' const url = 'https://utils.coryd.dev/api/now?endpoints=artists,albums,books,movies,tv'
const asset = new AssetCache('now_data') const res = EleventyFetch(url, {
if (asset.isCacheValid('1h')) return await asset.getCachedValue() duration: '1h',
const now = await fetch(url).then((res) => res.json()) type: 'json',
await asset.save(now, 'json') })
const now = await res
return { return {
artists: now.artists, artists: now.artists,
albums: now.albums, albums: now.albums,

View file

@ -1,15 +1,15 @@
const fetch = require('node-fetch') const EleventyFetch = require('@11ty/eleventy-fetch')
const { AssetCache } = require('@11ty/eleventy-fetch')
module.exports = async function () { module.exports = async function () {
const url = 'https://utils.coryd.dev/api/music?limit=1&period=7day' const url = 'https://utils.coryd.dev/api/music?limit=1&period=7day'
const asset = new AssetCache('now_playing_data') const res = EleventyFetch(url, {
if (asset.isCacheValid('3m')) return await asset.getCachedValue() duration: '0s',
const nowPlaying = await fetch(url).then((res) => res.json()) type: 'json',
await asset.save(nowPlaying, 'json') })
const music = await res
return { return {
artist: nowPlaying.recenttracks.track[0].artist['#text'], artist: music.recenttracks.track[0].artist['#text'],
title: nowPlaying.recenttracks.track[0].name, title: music.recenttracks.track[0].name,
url: nowPlaying.recenttracks.track[0].url, url: music.recenttracks.track[0].url,
} }
} }

View file

@ -1,11 +1,11 @@
const fetch = require('node-fetch') const EleventyFetch = require('@11ty/eleventy-fetch')
const { AssetCache } = require('@11ty/eleventy-fetch')
module.exports = async function () { module.exports = async function () {
const url = 'https://api.omg.lol/address/cory/statuses/' const url = 'https://api.omg.lol/address/cory/statuses/'
const asset = new AssetCache('status_data') const res = EleventyFetch(url, {
if (asset.isCacheValid('1h')) return await asset.getCachedValue() duration: '1d',
const status = await fetch(url).then((res) => res.json()) type: 'json',
await asset.save(status, 'json') })
const status = await res
return status.response.statuses[0] return status.response.statuses[0]
} }

View file

@ -1,12 +1,12 @@
const fetch = require('node-fetch') const EleventyFetch = require('@11ty/eleventy-fetch')
const { AssetCache } = require('@11ty/eleventy-fetch')
module.exports = async function () { module.exports = async function () {
const url = 'https://utils.coryd.dev/api/webmentions' const url = 'https://utils.coryd.dev/api/webmentions'
const asset = new AssetCache('webmentions_data') const res = EleventyFetch(url, {
if (asset.isCacheValid('1h')) return await asset.getCachedValue() duration: '1d',
const webmentions = await fetch(url).then((res) => res.json()) type: 'json',
await asset.save(webmentions, 'json') })
const webmentions = await res
return { return {
mentions: webmentions.children, mentions: webmentions.children,
} }