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