A new start
This commit is contained in:
35
packages/frontend/src/lib/directus.ts
Normal file
35
packages/frontend/src/lib/directus.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { authentication, createDirectus, rest } from "@directus/sdk";
|
||||
import { PUBLIC_API_URL } from "$env/static/public";
|
||||
import type { CurrentUser } from "./types";
|
||||
|
||||
export const directusApiUrl = 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 ? "?transform=" + 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;
|
||||
};
|
||||
Reference in New Issue
Block a user