2022-10-04 03:03:17 -05:00
|
|
|
import { basename, join } from 'path'
|
2021-08-17 01:26:20 -05:00
|
|
|
import { logger } from '@server/helpers/logger'
|
|
|
|
import { CONFIG } from '@server/initializers/config'
|
2022-10-12 09:09:02 -05:00
|
|
|
import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/models'
|
2021-08-17 01:26:20 -05:00
|
|
|
import { getHLSDirectory } from '../paths'
|
2022-10-12 09:09:02 -05:00
|
|
|
import { VideoPathManager } from '../video-path-manager'
|
2023-07-11 02:21:13 -05:00
|
|
|
import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebVideoObjectStorageKey } from './keys'
|
2022-10-19 03:43:53 -05:00
|
|
|
import {
|
|
|
|
createObjectReadStream,
|
|
|
|
listKeysOfPrefix,
|
|
|
|
lTags,
|
|
|
|
makeAvailable,
|
|
|
|
removeObject,
|
2022-10-25 07:18:59 -05:00
|
|
|
removeObjectByFullKey,
|
2022-10-19 03:43:53 -05:00
|
|
|
removePrefix,
|
2023-05-19 07:44:25 -05:00
|
|
|
storeContent,
|
2022-10-19 03:43:53 -05:00
|
|
|
storeObject,
|
|
|
|
updateObjectACL,
|
|
|
|
updatePrefixACL
|
|
|
|
} from './shared'
|
2021-08-17 01:26:20 -05:00
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
|
|
|
|
return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) {
|
2021-08-17 01:26:20 -05:00
|
|
|
return storeObject({
|
2022-10-04 03:03:17 -05:00
|
|
|
inputPath: join(getHLSDirectory(playlist.Video), filename),
|
2021-11-18 07:35:08 -06:00
|
|
|
objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
|
2022-10-19 03:43:53 -05:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
|
|
|
|
isPrivate: playlist.Video.hasPrivateStaticPath()
|
2021-08-17 01:26:20 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) {
|
|
|
|
return storeObject({
|
|
|
|
inputPath: path,
|
|
|
|
objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)),
|
2022-10-19 03:43:53 -05:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
|
|
|
|
isPrivate: playlist.Video.hasPrivateStaticPath()
|
2022-10-04 03:03:17 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-10 04:16:05 -05:00
|
|
|
function storeHLSFileFromContent (playlist: MStreamingPlaylistVideo, path: string, content: string) {
|
2023-05-19 07:44:25 -05:00
|
|
|
return storeContent({
|
|
|
|
content,
|
2023-05-10 04:16:05 -05:00
|
|
|
inputPath: path,
|
|
|
|
objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)),
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
|
|
|
|
isPrivate: playlist.Video.hasPrivateStaticPath()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
function storeWebVideoFile (video: MVideo, file: MVideoFile) {
|
2021-08-17 01:26:20 -05:00
|
|
|
return storeObject({
|
2022-10-12 09:09:02 -05:00
|
|
|
inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file),
|
2023-07-11 02:21:13 -05:00
|
|
|
objectStorageKey: generateWebVideoObjectStorageKey(file.filename),
|
2022-10-19 03:43:53 -05:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS,
|
|
|
|
isPrivate: video.hasPrivateStaticPath()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
async function updateWebVideoFileACL (video: MVideo, file: MVideoFile) {
|
2023-01-12 01:41:16 -06:00
|
|
|
await updateObjectACL({
|
2023-07-11 02:21:13 -05:00
|
|
|
objectStorageKey: generateWebVideoObjectStorageKey(file.filename),
|
2022-10-19 03:43:53 -05:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS,
|
|
|
|
isPrivate: video.hasPrivateStaticPath()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:41:16 -06:00
|
|
|
async function updateHLSFilesACL (playlist: MStreamingPlaylistVideo) {
|
|
|
|
await updatePrefixACL({
|
2022-10-19 03:43:53 -05:00
|
|
|
prefix: generateHLSObjectBaseStorageKey(playlist),
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
|
|
|
|
isPrivate: playlist.Video.hasPrivateStaticPath()
|
2021-08-17 01:26:20 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-11-18 07:35:08 -06:00
|
|
|
function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
|
|
|
|
return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
2021-08-17 01:26:20 -05:00
|
|
|
}
|
|
|
|
|
2022-10-25 07:18:59 -05:00
|
|
|
function removeHLSFileObjectStorageByFilename (playlist: MStreamingPlaylistVideo, filename: string) {
|
2022-07-25 03:57:16 -05:00
|
|
|
return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
2022-10-25 07:18:59 -05:00
|
|
|
function removeHLSFileObjectStorageByPath (playlist: MStreamingPlaylistVideo, path: string) {
|
|
|
|
return removeObject(generateHLSObjectStorageKey(playlist, basename(path)), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeHLSFileObjectStorageByFullKey (key: string) {
|
|
|
|
return removeObjectByFullKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
function removeWebVideoObjectStorage (videoFile: MVideoFile) {
|
|
|
|
return removeObject(generateWebVideoObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
|
2021-08-17 01:26:20 -05:00
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-11-18 07:35:08 -06:00
|
|
|
async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
|
|
|
|
const key = generateHLSObjectStorageKey(playlist, filename)
|
2021-08-17 01:26:20 -05:00
|
|
|
|
|
|
|
logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags())
|
|
|
|
|
|
|
|
await makeAvailable({
|
|
|
|
key,
|
|
|
|
destination,
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
|
|
|
|
})
|
|
|
|
|
|
|
|
return destination
|
|
|
|
}
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
async function makeWebVideoFileAvailable (filename: string, destination: string) {
|
|
|
|
const key = generateWebVideoObjectStorageKey(filename)
|
2021-08-17 01:26:20 -05:00
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
logger.info('Fetching Web Video file %s from object storage to %s.', key, destination, lTags())
|
2021-08-17 01:26:20 -05:00
|
|
|
|
|
|
|
await makeAvailable({
|
|
|
|
key,
|
|
|
|
destination,
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
|
|
|
|
})
|
|
|
|
|
|
|
|
return destination
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
function getWebVideoFileReadStream (options: {
|
2022-10-19 03:43:53 -05:00
|
|
|
filename: string
|
|
|
|
rangeHeader: string
|
|
|
|
}) {
|
|
|
|
const { filename, rangeHeader } = options
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
const key = generateWebVideoObjectStorageKey(filename)
|
2022-10-19 03:43:53 -05:00
|
|
|
|
|
|
|
return createObjectReadStream({
|
|
|
|
key,
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS,
|
|
|
|
rangeHeader
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHLSFileReadStream (options: {
|
|
|
|
playlist: MStreamingPlaylistVideo
|
|
|
|
filename: string
|
|
|
|
rangeHeader: string
|
|
|
|
}) {
|
|
|
|
const { playlist, filename, rangeHeader } = options
|
|
|
|
|
|
|
|
const key = generateHLSObjectStorageKey(playlist, filename)
|
|
|
|
|
|
|
|
return createObjectReadStream({
|
|
|
|
key,
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
|
|
|
|
rangeHeader
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-08-17 01:26:20 -05:00
|
|
|
export {
|
2022-10-04 03:03:17 -05:00
|
|
|
listHLSFileKeysOf,
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
storeWebVideoFile,
|
2022-10-04 03:03:17 -05:00
|
|
|
storeHLSFileFromFilename,
|
|
|
|
storeHLSFileFromPath,
|
2023-05-10 04:16:05 -05:00
|
|
|
storeHLSFileFromContent,
|
2021-08-17 01:26:20 -05:00
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
updateWebVideoFileACL,
|
2022-10-19 03:43:53 -05:00
|
|
|
updateHLSFilesACL,
|
|
|
|
|
2021-08-17 01:26:20 -05:00
|
|
|
removeHLSObjectStorage,
|
2022-10-25 07:18:59 -05:00
|
|
|
removeHLSFileObjectStorageByFilename,
|
|
|
|
removeHLSFileObjectStorageByPath,
|
|
|
|
removeHLSFileObjectStorageByFullKey,
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
removeWebVideoObjectStorage,
|
2021-08-17 01:26:20 -05:00
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
makeWebVideoFileAvailable,
|
2022-10-19 03:43:53 -05:00
|
|
|
makeHLSFileAvailable,
|
|
|
|
|
2023-07-11 02:21:13 -05:00
|
|
|
getWebVideoFileReadStream,
|
2022-10-19 03:43:53 -05:00
|
|
|
getHLSFileReadStream
|
2021-08-17 01:26:20 -05:00
|
|
|
}
|