chore: 调整目录结构
- 将Directus相关的组合式API移入composables/direcuts
This commit is contained in:
22
app/composables/directus/useDirectusFiles.ts
Normal file
22
app/composables/directus/useDirectusFiles.ts
Normal file
@ -0,0 +1,22 @@
|
||||
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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user