Files
sexy/packages/frontend/src/lib/directus.ts
Sebastian Krüger de16b64255
All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 5m13s
fix: use env object from \$env/dynamic/public instead of named imports
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 17:19:26 +01:00

36 lines
985 B
TypeScript

import { authentication, createDirectus, rest } from "@directus/sdk";
import { env } from "$env/dynamic/public";
import type { CurrentUser } from "./types";
export const directusApiUrl = env.PUBLIC_API_URL || "http://localhost:3000/api";
export const getDirectusInstance = (fetch?: typeof globalThis.fetch) => {
const options: { globals?: { fetch: typeof globalThis.fetch } } = fetch
? { globals: { fetch } }
: {};
const directus = createDirectus(directusApiUrl, options)
.with(rest())
.with(authentication("session"));
return directus;
};
export const getAssetUrl = (
id: string,
transform?: "mini" | "thumbnail" | "preview" | "medium" | "banner",
) => {
if (!id) {
return null;
}
return `${directusApiUrl}/assets/${id}${transform ? "?key=" + transform : ""}`;
};
export const isModel = (user: CurrentUser) => {
if (user.role.name === "Model") {
return true;
}
if (user.policies.find((p) => p.policy.name === "Model")) {
return true;
}
return false;
};