Line data Source code
1 2356 : const MEDIA_ROUTE =
2 : /^(?:\/api)?\/(?:view|viewvideo|vhs\/viewvideo|vhs\/viewaudio|assets\/[^/?#]+\/content)(?:[?#]|$)/
3 :
4 429 : export function isMediaRoute(route: string): boolean {
5 429 : return MEDIA_ROUTE.test(route)
6 : }
7 :
8 : /**
9 : * Names the workspace on a media route, which an image or video tag loads
10 : * without headers; absent means the personal workspace.
11 : */
12 0 : export function scopeMediaRoute(
13 : route: string,
14 : workspaceId: string | undefined
15 : ): string {
16 0 : if (!workspaceId || !isMediaRoute(route)) return route
17 0 : const hashStart = route.indexOf('#')
18 0 : const path = hashStart === -1 ? route : route.slice(0, hashStart)
19 0 : const fragment = hashStart === -1 ? '' : route.slice(hashStart)
20 0 : if (/[?&]workspace_id=/.test(path)) return route
21 : const separator = path.includes('?') ? '&' : '?'
22 0 : return `${path}${separator}workspace_id=${encodeURIComponent(workspaceId)}${fragment}`
23 : }
|