Files
kopyl.dev.v2/src/routes/+page.server.ts
Anatoly Kopyl d14efb7aae
All checks were successful
Deploy / build-and-publish (push) Successful in 1m24s
Deploy / deploy (push) Successful in 11s
Revert "Don't wait for stars update"
This reverts commit 17bef7f18c.
2024-09-30 02:52:31 +03:00

25 lines
502 B
TypeScript

import type {PageServerLoad} from "./$types";
import getStars from "$lib/getStars";
const CACHE_LIFE = 1000 * 60 * 5
let lastRequest = Date.now()
let starCount: number | null = null
export const load: PageServerLoad = async () => {
const now = Date.now()
if (now - CACHE_LIFE > lastRequest || starCount === null) {
lastRequest = Date.now()
try {
starCount = await getStars('anatolykopyl')
} catch (error) {
console.log(error)
}
}
return {
starCount,
};
}