(frontend) create utility for media download URL generation

Encapsulate URL base generation logic for media downloads into a reusable
utility function, mirroring the approach used in the API. Improves code
consistency and reduces duplication across frontend components.
This commit is contained in:
lebaudantoine
2025-04-17 15:32:50 +02:00
committed by aleb_the_flash
parent 67967f00b5
commit 06462a55b0

View File

@@ -0,0 +1,11 @@
export const mediaUrl = (path: string) => {
const origin =
import.meta.env.VITE_API_BASE_URL ||
(typeof window !== 'undefined' ? window.location.origin : '')
// Remove leading/trailing slashes from origin/path if it exists
const sanitizedOrigin = origin.replace(/\/$/, '')
const sanitizedPath = path.replace(/^\//, '')
return `${sanitizedOrigin}/media/${sanitizedPath}`
}