chore: added logging
All checks were successful
Publish and deploy / publish (push) Successful in 37s
Publish and deploy / deploy (push) Successful in 7s

This commit is contained in:
alina 🌸 2025-01-28 06:49:05 +03:00
parent c725207173
commit 05562a8a6f
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
2 changed files with 14 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import { ffetch } from '../utils/fetch.ts'
const WEBRING_URL = 'https://otomir23.me/webring/5/data' const WEBRING_URL = 'https://otomir23.me/webring/5/data'
const WEBRING_TTL = 1000 * 60 * 60 * 24 // 24 hours const WEBRING_TTL = 1000 * 60 * 60 * 24 // 24 hours
const STALE_TTL = 1000 * 60 * 60 * 8 // 8 hours
const WebringItem = z.object({ const WebringItem = z.object({
id: z.number(), id: z.number(),
@ -29,4 +30,5 @@ export const webring = new AsyncResource<WebringData>({
} }
}, },
swr: true, swr: true,
swrValidator: ({ currentFetchedAt }) => Date.now() - currentFetchedAt < STALE_TTL,
}) })

View file

@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { ffetchAddons, ffetchBase } from '@fuman/fetch' import { ffetchAddons, ffetchBase } from '@fuman/fetch'
import { ffetchZodAdapter } from '@fuman/fetch/zod' import { ffetchZodAdapter } from '@fuman/fetch/zod'
@ -6,6 +7,17 @@ export const ffetch = ffetchBase.extend({
ffetchAddons.parser(ffetchZodAdapter()), ffetchAddons.parser(ffetchZodAdapter()),
ffetchAddons.retry(), ffetchAddons.retry(),
], ],
middlewares: [
async (req, next) => {
console.log('[%s] fetch(%s %s)', new Date().toISOString(), req.method, req.url)
const start = Date.now()
try {
return await next(req)
} finally {
console.log('[%s] fetch(%s %s) done in %sms', new Date().toISOString(), req.method, req.url, Date.now() - start)
}
},
],
headers: { headers: {
'User-Agent': 'tei.su/1.0', 'User-Agent': 'tei.su/1.0',
}, },