All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 5m13s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
985 B
TypeScript
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;
|
|
};
|