Move get asset function into same API file

This commit is contained in:
2022-08-14 12:12:30 +02:00
parent f504b45957
commit fa74e5bf7f
5 changed files with 38 additions and 39 deletions

View File

@@ -27,4 +27,38 @@ export const fetchAPI = async (query: string) => {
} catch (error) {
console.error(error)
}
}
}
/**
* Get a Directus asset URL from parameters
*/
export const getAssetUrlKey = (
id: string,
key: string
) => {
if (!id || !key) return null
return `${API_URL}/assets/${id}?key=${key}`
}
/**
* 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 `${API_URL}/assets/${id}?width=${width}&height=${height}&fit=${fit}${args}`
// }