Create helper function for getting asset URL from API
This commit is contained in:
19
src/utils/helpers.ts
Normal file
19
src/utils/helpers.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Get a Directus asset URL from parameters
|
||||
*/
|
||||
export const getAssetUrl = (
|
||||
id: string,
|
||||
width: number,
|
||||
height: number,
|
||||
quality?: number,
|
||||
fit: string = 'inside',
|
||||
format?: string
|
||||
) => {
|
||||
let args = ''
|
||||
|
||||
// Add arguments to URL if specified
|
||||
if (quality) args += `&quality=${quality}`
|
||||
if (format) args += `&format=${format}`
|
||||
|
||||
return `${import.meta.env.VITE_API_URL_DEV}/assets/${id}?width=${width}&height=${height}&fit=${fit}${args}`
|
||||
}
|
||||
Reference in New Issue
Block a user