2026-09-11 11:25:14 +02:00
|
|
|
import type { MediaImage } from '#shared/types/blog'
|
2026-08-25 11:42:17 +02:00
|
|
|
|
|
|
|
|
/**
|
2026-09-11 11:25:14 +02:00
|
|
|
* PocketBase returns file paths relative to its own origin; the browser
|
|
|
|
|
* needs absolute ones.
|
2026-08-25 11:42:17 +02:00
|
|
|
*/
|
|
|
|
|
export function useMediaUrl() {
|
|
|
|
|
const { public: config } = useRuntimeConfig()
|
|
|
|
|
|
2026-09-11 11:25:14 +02:00
|
|
|
return (image: MediaImage | null | undefined): string | null => {
|
2026-08-25 11:42:17 +02:00
|
|
|
if (!image?.url) return null
|
2026-09-11 11:25:14 +02:00
|
|
|
return image.url.startsWith('http') ? image.url : `${config.pocketbaseUrl}${image.url}`
|
2026-08-25 11:42:17 +02:00
|
|
|
}
|
|
|
|
|
}
|