Added caching
This commit is contained in:
@@ -1,9 +1,20 @@
|
||||
import { cacheLife } from "next/dist/server/use-cache/cache-life"
|
||||
import { env } from "../../env/server"
|
||||
import { guildSchema } from "../../schema/guild"
|
||||
|
||||
const guildApi = "https://api.hypixel.net/v2/guild"
|
||||
|
||||
export async function getGuild(id: string, type: "id" | "player" | "name" = "player") {
|
||||
"use cache"
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
cacheLife({
|
||||
stale: 1000 * 60,
|
||||
revalidate: 1000 * 60 * 5,
|
||||
expire: 1000 * 60 * 5
|
||||
})
|
||||
}
|
||||
|
||||
const res = await fetch(`${guildApi}?${type}=${id}`, {
|
||||
headers: {
|
||||
"API-Key": env.HYPIXEL_API_KEY
|
||||
@@ -17,4 +28,5 @@ export async function getGuild(id: string, type: "id" | "player" | "name" = "pla
|
||||
if (!success) return null
|
||||
|
||||
return data.guild
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { cacheLife } from "next/dist/server/use-cache/cache-life"
|
||||
import z from "zod"
|
||||
|
||||
const mojangApi = "https://api.mojang.com/users/profiles/minecraft"
|
||||
@@ -8,6 +9,16 @@ const schema = z.object({
|
||||
})
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
const res = await fetch(`${mojangApi}/${ign}`)
|
||||
|
||||
if (!res.ok) return null
|
||||
@@ -20,4 +31,3 @@ export async function getUuid(ign: string) {
|
||||
|
||||
return parsed.data
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import { cacheLife } from "next/dist/server/use-cache/cache-life"
|
||||
import { env } from "../../env/server"
|
||||
import { playerSchema } from "../../schema/player"
|
||||
|
||||
const playerApi = "https://api.hypixel.net/v2/player"
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
const res = await fetch(`${playerApi}?uuid=${uuid}`, {
|
||||
headers: {
|
||||
"API-Key": env.HYPIXEL_API_KEY
|
||||
|
||||
Reference in New Issue
Block a user