Files
sexy/packages/frontend/src/lib/api.ts

26 lines
740 B
TypeScript
Raw Normal View History

import { GraphQLClient } from "graphql-request";
import { env } from "$env/dynamic/public";
import type { CurrentUser } from "./types";
export const apiUrl = env.PUBLIC_API_URL || "http://localhost:3000/api";
export const getGraphQLClient = (fetchFn?: typeof globalThis.fetch) =>
new GraphQLClient(`${apiUrl}/graphql`, {
credentials: "include",
fetch: fetchFn || globalThis.fetch,
});
export const getAssetUrl = (
id: string | null | undefined,
transform?: "mini" | "thumbnail" | "preview" | "medium" | "banner",
) => {
if (!id) {
return null;
}
return `${apiUrl}/assets/${id}${transform ? "?transform=" + transform : ""}`;
};
export const isModel = (user: CurrentUser) => {
return user.role === "model";
};