2023-07-31 14:34:36 +02:00
|
|
|
import { OBJECT_STORAGE_PROXY_PATHS, WEBSERVER } from '@server/initializers/constants.js'
|
|
|
|
import { MVideoUUID } from '@server/types/models/index.js'
|
|
|
|
import { BucketInfo, buildKey, getEndpointParsed } from './shared/index.js'
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export function getInternalUrl (config: BucketInfo, keyWithoutPrefix: string) {
|
2021-08-17 08:26:20 +02:00
|
|
|
return getBaseUrl(config) + buildKey(keyWithoutPrefix, config)
|
|
|
|
}
|
|
|
|
|
2022-10-19 10:43:53 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export function getObjectStoragePublicFileUrl (fileUrl: string, objectStorageConfig: { BASE_URL: string }) {
|
|
|
|
const baseUrl = objectStorageConfig.BASE_URL
|
2021-08-17 08:26:20 +02:00
|
|
|
if (!baseUrl) return fileUrl
|
|
|
|
|
|
|
|
return replaceByBaseUrl(fileUrl, baseUrl)
|
|
|
|
}
|
|
|
|
|
2022-10-19 10:43:53 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export function getHLSPrivateFileUrl (video: MVideoUUID, filename: string) {
|
2022-10-19 10:43:53 +02:00
|
|
|
return WEBSERVER.URL + OBJECT_STORAGE_PROXY_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS + video.uuid + `/${filename}`
|
|
|
|
}
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export function getWebVideoPrivateFileUrl (filename: string) {
|
2023-07-11 11:39:59 +02:00
|
|
|
return WEBSERVER.URL + OBJECT_STORAGE_PROXY_PATHS.PRIVATE_WEB_VIDEOS + filename
|
2022-10-19 10:43:53 +02:00
|
|
|
}
|
2021-08-17 08:26:20 +02: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 08:30:56 +01:00
|
|
|
if (!fileUrl) return fileUrl
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
return fileUrl.replace(regex, baseUrl)
|
|
|
|
}
|