]>
Commit | Line | Data |
---|---|---|
1 | import { CONFIG } from '@server/initializers/config' | |
2 | import { BucketInfo, buildKey, getEndpointParsed } from './shared' | |
3 | ||
4 | function getPrivateUrl (config: BucketInfo, keyWithoutPrefix: string) { | |
5 | return getBaseUrl(config) + buildKey(keyWithoutPrefix, config) | |
6 | } | |
7 | ||
8 | function getWebTorrentPublicFileUrl (fileUrl: string) { | |
9 | const baseUrl = CONFIG.OBJECT_STORAGE.VIDEOS.BASE_URL | |
10 | if (!baseUrl) return fileUrl | |
11 | ||
12 | return replaceByBaseUrl(fileUrl, baseUrl) | |
13 | } | |
14 | ||
15 | function getHLSPublicFileUrl (fileUrl: string) { | |
16 | const baseUrl = CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BASE_URL | |
17 | if (!baseUrl) return fileUrl | |
18 | ||
19 | return replaceByBaseUrl(fileUrl, baseUrl) | |
20 | } | |
21 | ||
22 | export { | |
23 | getPrivateUrl, | |
24 | getWebTorrentPublicFileUrl, | |
25 | replaceByBaseUrl, | |
26 | getHLSPublicFileUrl | |
27 | } | |
28 | ||
29 | // --------------------------------------------------------------------------- | |
30 | ||
31 | function getBaseUrl (bucketInfo: BucketInfo, baseUrl?: string) { | |
32 | if (baseUrl) return baseUrl | |
33 | ||
34 | return `${getEndpointParsed().protocol}//${bucketInfo.BUCKET_NAME}.${getEndpointParsed().host}/` | |
35 | } | |
36 | ||
37 | const regex = new RegExp('https?://[^/]+') | |
38 | function replaceByBaseUrl (fileUrl: string, baseUrl: string) { | |
39 | return fileUrl.replace(regex, baseUrl) | |
40 | } |