✨(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:
committed by
aleb_the_flash
parent
67967f00b5
commit
06462a55b0
11
src/frontend/src/api/mediaUrl.ts
Normal file
11
src/frontend/src/api/mediaUrl.ts
Normal 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}`
|
||||
}
|
||||
Reference in New Issue
Block a user