Files
Adam Hathcock 377cfc2f65 Feat(preview): get preview image over rest api (#8)
* pass token to the model card to allow it to be used when loading a preview

* fix lint conditons

* composable for preview url and reuse in version and model cards

* remove unused import

* handle no version scenario

* remove console log

---------

Co-authored-by: oguzhankoral <oguzhankoral@gmail.com>
2025-05-20 20:53:52 +03:00

18 lines
526 B
TypeScript

/**
* @param previewUrl url that server returns but does not return the corresponding image if the project is private
* @param token auth token to get proper image over url
*/
export async function usePreviewUrl(
token: string,
previewUrl?: string
): Promise<string | undefined> {
if (!previewUrl) return previewUrl
const res = await fetch(previewUrl, {
headers: { Authorization: `Bearer ${token}` }
})
if (!res.ok) return previewUrl //
const blob = await res.blob()
return URL.createObjectURL(blob)
}