Files
jinshen-website/app/composables/directus/useDirectusImage.ts
R2m1liA a520775a8d
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m2s
refactor: 将文件请求由app端转到server端
2025-11-12 18:19:21 +08:00

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 };
};