23 lines
535 B
TypeScript
23 lines
535 B
TypeScript
export const useDirectusFiles = () => {
|
|
const config = useRuntimeConfig();
|
|
const baseUrl = config.public.directus.url;
|
|
|
|
const getFileUrl = (
|
|
id?: string | null,
|
|
options?: Record<string, string | number | boolean>
|
|
): string => {
|
|
if (!id) return '';
|
|
const query = options
|
|
? '?' +
|
|
new URLSearchParams(
|
|
Object.entries(options).map(([key, value]) => [key, String(value)])
|
|
).toString()
|
|
: '';
|
|
return `${baseUrl}/assets/${id}${query}`;
|
|
};
|
|
|
|
return {
|
|
getFileUrl,
|
|
};
|
|
};
|