Files

15 lines
439 B
TypeScript
Raw Permalink Normal View History

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