15 lines
486 B
TypeScript
15 lines
486 B
TypeScript
import type { StrapiImage } from '#shared/types/blog'
|
|||
|
|
|
||
|
|
/**
|
||
|
|
* Strapi returns media paths relative to its own origin; the browser needs
|
||
|
|
* absolute ones. Remote providers (S3) already return absolute URLs.
|
||
|
|
*/
|
||
|
|
export function useMediaUrl() {
|
||
|
|
const { public: config } = useRuntimeConfig()
|
||
|
|
|
||
|
|
return (image: StrapiImage | null | undefined): string | null => {
|
||
|
|
if (!image?.url) return null
|
||
|
|
return image.url.startsWith('http') ? image.url : `${config.strapiUrl}${image.url}`
|
||
|
|
}
|
||
|
|
}
|