26 lines
721 B
TypeScript
26 lines
721 B
TypeScript
|
|
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,
|
||
|
|
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";
|
||
|
|
};
|