2021-08-17 01:26:20 -05:00
|
|
|
import { CONFIG } from '@server/initializers/config'
|
2022-10-19 03:43:53 -05:00
|
|
|
import { OBJECT_STORAGE_PROXY_PATHS, WEBSERVER } from '@server/initializers/constants'
|
|
|
|
import { MVideoUUID } from '@server/types/models'
|
2021-08-17 01:26:20 -05:00
|
|
|
import { BucketInfo, buildKey, getEndpointParsed } from './shared'
|
|
|
|
|
2022-10-19 03:43:53 -05:00
|
|
|
function getInternalUrl (config: BucketInfo, keyWithoutPrefix: string) {
|
2021-08-17 01:26:20 -05:00
|
|
|
return getBaseUrl(config) + buildKey(keyWithoutPrefix, config)
|
|
|
|
}
|
|
|
|
|
2022-10-19 03:43:53 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
function getWebVideoPublicFileUrl (fileUrl: string) {
|
2023-07-11 04:23:51 -05:00
|
|
|
const baseUrl = CONFIG.OBJECT_STORAGE.WEB_VIDEOS.BASE_URL
|
2021-08-17 01:26:20 -05:00
|
|
|
if (!baseUrl) return fileUrl
|
|
|
|
|
|
|
|
return replaceByBaseUrl(fileUrl, baseUrl)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHLSPublicFileUrl (fileUrl: string) {
|
|
|
|
const baseUrl = CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BASE_URL
|
|
|
|
if (!baseUrl) return fileUrl
|
|
|
|
|
|
|
|
return replaceByBaseUrl(fileUrl, baseUrl)
|
|
|
|
}
|
|
|
|
|
2022-10-19 03:43:53 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function getHLSPrivateFileUrl (video: MVideoUUID, filename: string) {
|
|
|
|
return WEBSERVER.URL + OBJECT_STORAGE_PROXY_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS + video.uuid + `/${filename}`
|
|
|
|
}
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
function getWebVideoPrivateFileUrl (filename: string) {
|
2023-07-11 04:39:59 -05:00
|
|
|
return WEBSERVER.URL + OBJECT_STORAGE_PROXY_PATHS.PRIVATE_WEB_VIDEOS + filename
|
2022-10-19 03:43:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-08-17 01:26:20 -05:00
|
|
|
export {
|
2022-10-19 03:43:53 -05:00
|
|
|
getInternalUrl,
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
getWebVideoPublicFileUrl,
|
2022-10-19 03:43:53 -05:00
|
|
|
getHLSPublicFileUrl,
|
|
|
|
|
|
|
|
getHLSPrivateFileUrl,
|
2023-07-11 02:21:13 -05:00
|
|
|
getWebVideoPrivateFileUrl,
|
2022-10-19 03:43:53 -05:00
|
|
|
|
|
|
|
replaceByBaseUrl
|
2021-08-17 01:26:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function getBaseUrl (bucketInfo: BucketInfo, baseUrl?: string) {
|
|
|
|
if (baseUrl) return baseUrl
|
|
|
|
|
|
|
|
return `${getEndpointParsed().protocol}//${bucketInfo.BUCKET_NAME}.${getEndpointParsed().host}/`
|
|
|
|
}
|
|
|
|
|
|
|
|
const regex = new RegExp('https?://[^/]+')
|
|
|
|
function replaceByBaseUrl (fileUrl: string, baseUrl: string) {
|
2023-01-27 01:30:56 -06:00
|
|
|
if (!fileUrl) return fileUrl
|
|
|
|
|
2021-08-17 01:26:20 -05:00
|
|
|
return fileUrl.replace(regex, baseUrl)
|
|
|
|
}
|