2023-07-31 07:34:36 -05:00
|
|
|
import { logger } from '@server/helpers/logger.js'
|
|
|
|
import { CONFIG } from '@server/initializers/config.js'
|
|
|
|
import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/models/index.js'
|
2024-03-15 09:47:18 -05:00
|
|
|
import { MVideoSource } from '@server/types/models/video/video-source.js'
|
|
|
|
import { basename, join } from 'path'
|
2023-07-31 07:34:36 -05:00
|
|
|
import { getHLSDirectory } from '../paths.js'
|
|
|
|
import { VideoPathManager } from '../video-path-manager.js'
|
2024-03-15 09:47:18 -05:00
|
|
|
import {
|
|
|
|
generateHLSObjectBaseStorageKey,
|
|
|
|
generateHLSObjectStorageKey,
|
|
|
|
generateOriginalVideoObjectStorageKey,
|
|
|
|
generateWebVideoObjectStorageKey
|
|
|
|
} from './keys.js'
|
2022-10-19 03:43:53 -05:00
|
|
|
import {
|
|
|
|
createObjectReadStream,
|
|
|
|
lTags,
|
2024-03-15 09:47:18 -05:00
|
|
|
listKeysOfPrefix,
|
2022-10-19 03:43:53 -05:00
|
|
|
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
|
2023-07-31 07:34:36 -05:00
|
|
|
} from './shared/index.js'
|
2021-08-17 01:26:20 -05:00
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
|
2022-10-04 03:03:17 -05:00
|
|
|
return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export 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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) {
|
2022-10-04 03:03:17 -05:00
|
|
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export 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
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export 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),
|
2023-07-11 04:23:51 -05:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS,
|
2022-10-19 03:43:53 -05:00
|
|
|
isPrivate: video.hasPrivateStaticPath()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function storeOriginalVideoFile (inputPath: string, filename: string) {
|
|
|
|
return storeObject({
|
|
|
|
inputPath,
|
|
|
|
objectStorageKey: generateOriginalVideoObjectStorageKey(filename),
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.ORIGINAL_VIDEO_FILES,
|
|
|
|
isPrivate: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export 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),
|
2023-07-11 04:23:51 -05:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS,
|
2022-10-19 03:43:53 -05:00
|
|
|
isPrivate: video.hasPrivateStaticPath()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export async function updateHLSFilesACL (playlist: MStreamingPlaylistVideo) {
|
2023-01-12 01:41:16 -06:00
|
|
|
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
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
|
2021-11-18 07:35:08 -06:00
|
|
|
return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
2021-08-17 01:26:20 -05:00
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function removeHLSFileObjectStorageByFilename (playlist: MStreamingPlaylistVideo, filename: string) {
|
2022-07-25 03:57:16 -05:00
|
|
|
return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function removeHLSFileObjectStorageByPath (playlist: MStreamingPlaylistVideo, path: string) {
|
2022-10-25 07:18:59 -05:00
|
|
|
return removeObject(generateHLSObjectStorageKey(playlist, basename(path)), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function removeHLSFileObjectStorageByFullKey (key: string) {
|
2022-10-25 07:18:59 -05:00
|
|
|
return removeObjectByFullKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function removeWebVideoObjectStorage (videoFile: MVideoFile) {
|
2023-07-11 04:23:51 -05:00
|
|
|
return removeObject(generateWebVideoObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.WEB_VIDEOS)
|
2021-08-17 01:26:20 -05:00
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function removeOriginalFileObjectStorage (videoSource: MVideoSource) {
|
|
|
|
return removeObject(generateOriginalVideoObjectStorageKey(videoSource.keptOriginalFilename), CONFIG.OBJECT_STORAGE.ORIGINAL_VIDEO_FILES)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
|
2021-11-18 07:35:08 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export async function makeWebVideoFileAvailable (filename: string, destination: string) {
|
2023-07-11 02:21:13 -05:00
|
|
|
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,
|
2023-07-11 04:23:51 -05:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS
|
2021-08-17 01:26:20 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
return destination
|
|
|
|
}
|
|
|
|
|
2024-06-04 02:08:24 -05:00
|
|
|
export async function makeOriginalFileAvailable (keptOriginalFilename: string, destination: string) {
|
|
|
|
const key = generateOriginalVideoObjectStorageKey(keptOriginalFilename)
|
|
|
|
|
|
|
|
logger.info('Fetching Original Video file %s from object storage to %s.', key, destination, lTags())
|
|
|
|
|
|
|
|
await makeAvailable({
|
|
|
|
key,
|
|
|
|
destination,
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.ORIGINAL_VIDEO_FILES
|
|
|
|
})
|
|
|
|
|
|
|
|
return destination
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export 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,
|
2023-07-11 04:23:51 -05:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS,
|
2022-10-19 03:43:53 -05:00
|
|
|
rangeHeader
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function getHLSFileReadStream (options: {
|
2022-10-19 03:43:53 -05:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
export function getOriginalFileReadStream (options: {
|
|
|
|
keptOriginalFilename: string
|
|
|
|
rangeHeader: string
|
|
|
|
}) {
|
|
|
|
const { keptOriginalFilename, rangeHeader } = options
|
2021-08-17 01:26:20 -05:00
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
const key = generateOriginalVideoObjectStorageKey(keptOriginalFilename)
|
2022-10-19 03:43:53 -05:00
|
|
|
|
2024-03-15 09:47:18 -05:00
|
|
|
return createObjectReadStream({
|
|
|
|
key,
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.ORIGINAL_VIDEO_FILES,
|
|
|
|
rangeHeader
|
|
|
|
})
|
2021-08-17 01:26:20 -05:00
|
|
|
}
|