Something went wrong. Try again.
The weeb for the next gen discord boat - Wamellow wamellow.com
bot discord
Something went wrong. Try again.
1.2 kB · 42 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142import type { ApiError, ApiV1GuildsGetResponse } from "@/typings";
import { ApiClient } from "./client";
export interface ApiRequestOptions { force?: boolean;}
export const cacheOptions = { gcTime: 1_000 * 60 * 60, refetchOnWindowFocus: false, refetchOnMount: false};
export const defaultFetchOptions = { headers: { Authorization: process.env.API_SECRET as string }, next: { revalidate: 60 * 60 }};
/* @deprecated Use `client.get` instead */export async function getData<T>(path: string) { const response = await fetch(`${process.env.NEXT_PUBLIC_API}${path}`, { credentials: "include" });
return response.json() as Promise<T | ApiError>;}
export const client = new ApiClient(process.env.NEXT_PUBLIC_API!);
export async function getGuild(guildId?: string | null, options?: ApiRequestOptions): Promise<ApiV1GuildsGetResponse | ApiError | undefined> { if (!guildId) return;
const res = await fetch(`${process.env.NEXT_PUBLIC_API}/guilds/${guildId}`, { headers: { Authorization: process.env.API_SECRET as string }, next: options?.force ? { revalidate: 0 } : { revalidate: 60 * 60 } });
return res.json();}