All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m2s
21 lines
582 B
TypeScript
21 lines
582 B
TypeScript
export const useDirectusImage = () => {
|
|
type DirectusAssetParams = {
|
|
width?: number;
|
|
height?: number;
|
|
fit?: 'cover' | 'contain' | 'inside' | 'outside';
|
|
quality?: number;
|
|
format?: 'webp' | 'jpg' | 'png' | 'auto';
|
|
} & Record<string, string | number | boolean>;
|
|
|
|
const getImageUrl = (id?: string | null, options?: DirectusAssetParams) => {
|
|
if (!id) return '';
|
|
|
|
const params = new URLSearchParams(
|
|
options as Record<string, string>
|
|
).toString();
|
|
return `/api/assets/${id}${params ? `?${params}` : ''}`;
|
|
};
|
|
|
|
return { getImageUrl };
|
|
};
|