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