1 import { CONFIG } from '@server/initializers/config'
2 import { BucketInfo, buildKey, getEndpointParsed } from './shared'
4 function getPrivateUrl (config: BucketInfo, keyWithoutPrefix: string) {
5 return getBaseUrl(config) + buildKey(keyWithoutPrefix, config)
8 function getWebTorrentPublicFileUrl (fileUrl: string) {
9 const baseUrl = CONFIG.OBJECT_STORAGE.VIDEOS.BASE_URL
10 if (!baseUrl) return fileUrl
12 return replaceByBaseUrl(fileUrl, baseUrl)
15 function getHLSPublicFileUrl (fileUrl: string) {
16 const baseUrl = CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BASE_URL
17 if (!baseUrl) return fileUrl
19 return replaceByBaseUrl(fileUrl, baseUrl)
24 getWebTorrentPublicFileUrl,
29 // ---------------------------------------------------------------------------
31 function getBaseUrl (bucketInfo: BucketInfo, baseUrl?: string) {
32 if (baseUrl) return baseUrl
34 return `${getEndpointParsed().protocol}//${bucketInfo.BUCKET_NAME}.${getEndpointParsed().host}/`
37 const regex = new RegExp('https?://[^/]+')
38 function replaceByBaseUrl (fileUrl: string, baseUrl: string) {
39 return fileUrl.replace(regex, baseUrl)