diff --git a/next.config.ts b/next.config.ts index 4ad5da4..6684d02 100644 --- a/next.config.ts +++ b/next.config.ts @@ -10,6 +10,23 @@ const nextConfig: NextConfig = { experimental: { browserDebugInfoInTerminal: true, turbopackFileSystemCacheForDev: true + }, + cacheLife: { + hypixelApi: { + stale: 1000 * 60, + revalidate: 1000 * 30, + expire: 1000 * 60 * 5 + }, + mojangApi: { + stale: 1000 * 60, + revalidate: 1000 * 30, + expire: 1000 * 60 * 5 + }, + playerWithGuild: { + stale: 1000 * 60 * 60 * 24, + revalidate: 1000 * 60 * 60 * 24, + expire: 1000 * 60 * 60 * 24 * 7 + } } } diff --git a/src/app/(stats)/player/[ign]/page.tsx b/src/app/(stats)/player/[ign]/page.tsx index b573d96..8bcb29e 100644 --- a/src/app/(stats)/player/[ign]/page.tsx +++ b/src/app/(stats)/player/[ign]/page.tsx @@ -12,7 +12,7 @@ import { Metadata } from "next" import { cookies } from "next/headers" import { Suspense } from "react" import z from "zod" -import { PlayerPageLoadText, PlayerStats } from "./_client" +import { PlayerStats } from "./_client" import Sidebar from "./_components/sidebar" export async function generateMetadata({ params }: PageProps<"/player/[ign]">): Promise { @@ -38,7 +38,6 @@ export default function PlayerPage({ params }: PageProps<"/player/[ign]">) { fallback={
-
} > diff --git a/src/components/ui/skeleton.tsx b/src/components/ui/skeleton.tsx new file mode 100644 index 0000000..3883d1a --- /dev/null +++ b/src/components/ui/skeleton.tsx @@ -0,0 +1,13 @@ +import { cn } from "@/lib/utils" + +function Skeleton({ className, ...props }: React.ComponentProps<"div">) { + return ( +
+ ) +} + +export { Skeleton } diff --git a/src/lib/hypixel/api/guild.ts b/src/lib/hypixel/api/guild.ts index 5409359..66a7ac2 100644 --- a/src/lib/hypixel/api/guild.ts +++ b/src/lib/hypixel/api/guild.ts @@ -8,11 +8,7 @@ export async function getGuild(id: string, type: "id" | "player" | "name" = "pla "use cache" if (process.env.NODE_ENV === "production") { - cacheLife({ - stale: 1000 * 60, - revalidate: 1000 * 60 * 5, - expire: 1000 * 60 * 5 - }) + cacheLife("hypixelApi") } const res = await fetch(`${guildApi}?${type}=${id}`, { diff --git a/src/lib/hypixel/api/mojang.ts b/src/lib/hypixel/api/mojang.ts index 775e0f5..ce2c83c 100644 --- a/src/lib/hypixel/api/mojang.ts +++ b/src/lib/hypixel/api/mojang.ts @@ -1,4 +1,5 @@ import { cacheLife } from "next/dist/server/use-cache/cache-life" +import { setTimeout } from "node:timers/promises" import z from "zod" const mojangApi = "https://api.mojang.com/users/profiles/minecraft" @@ -12,13 +13,11 @@ export async function getUuid(ign: string) { "use cache" if (process.env.NODE_ENV === "production") { - cacheLife({ - stale: 1000 * 60, - revalidate: 1000 * 60 * 5, - expire: 1000 * 60 * 5 - }) + cacheLife("mojangApi") } + await setTimeout(5000) + const res = await fetch(`${mojangApi}/${ign}`) if (!res.ok) return null diff --git a/src/lib/hypixel/api/online.ts b/src/lib/hypixel/api/online.ts index 0b404ca..9768e68 100644 --- a/src/lib/hypixel/api/online.ts +++ b/src/lib/hypixel/api/online.ts @@ -8,11 +8,7 @@ export async function getSession(uuid: string) { "use cache" if (process.env.NODE_ENV === "production") { - cacheLife({ - stale: 1000 * 60, - revalidate: 1000 * 60 * 5, - expire: 1000 * 60 * 5 - }) + cacheLife("hypixelApi") } const res = await fetch(`${playerApi}?uuid=${uuid}`, { diff --git a/src/lib/hypixel/api/player.ts b/src/lib/hypixel/api/player.ts index 8f11a66..7c67030 100644 --- a/src/lib/hypixel/api/player.ts +++ b/src/lib/hypixel/api/player.ts @@ -8,11 +8,7 @@ export async function getPlayerForGuild(uuid: string) { "use cache" // if (process.env.NODE_ENV === "production") { - cacheLife({ - stale: 1000 * 60 * 60, - revalidate: 1000 * 60 * 60 * 24 * 7, - expire: 1000 * 60 * 60 * 24 * 7 - }) + cacheLife("playerWithGuild") // } const res = await fetch(`${playerApi}?uuid=${uuid}`, { @@ -38,11 +34,7 @@ export async function getPlayer(uuid: string) { "use cache" if (process.env.NODE_ENV === "production") { - cacheLife({ - stale: 1000 * 60, - revalidate: 1000 * 60 * 5, - expire: 1000 * 60 * 5 - }) + cacheLife("hypixelApi") } const res = await fetch(`${playerApi}?uuid=${uuid}`, {