2022-10-04 04:03:17 -04:00
|
|
|
import { basename, join } from 'path'
|
2021-08-17 02:26:20 -04:00
|
|
|
import { logger } from '@server/helpers/logger'
|
|
|
|
import { CONFIG } from '@server/initializers/config'
|
2022-10-12 10:09:02 -04:00
|
|
|
import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/models'
|
2021-08-17 02:26:20 -04:00
|
|
|
import { getHLSDirectory } from '../paths'
|
2022-10-12 10:09:02 -04:00
|
|
|
import { VideoPathManager } from '../video-path-manager'
|
2021-08-17 02:26:20 -04:00
|
|
|
import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys'
|
2022-10-04 04:03:17 -04:00
|
|
|
import { listKeysOfPrefix, lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared'
|
2021-08-17 02:26:20 -04:00
|
|
|
|
2022-10-04 04:03:17 -04:00
|
|
|
function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
|
|
|
|
return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) {
|
2021-08-17 02:26:20 -04:00
|
|
|
return storeObject({
|
2022-10-04 04:03:17 -04:00
|
|
|
inputPath: join(getHLSDirectory(playlist.Video), filename),
|
2021-11-18 08:35:08 -05:00
|
|
|
objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
|
2021-08-17 02:26:20 -04:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-04 04:03:17 -04:00
|
|
|
function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) {
|
|
|
|
return storeObject({
|
|
|
|
inputPath: path,
|
|
|
|
objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)),
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2022-10-12 10:09:02 -04:00
|
|
|
function storeWebTorrentFile (video: MVideo, file: MVideoFile) {
|
2021-08-17 02:26:20 -04:00
|
|
|
return storeObject({
|
2022-10-12 10:09:02 -04:00
|
|
|
inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file),
|
|
|
|
objectStorageKey: generateWebTorrentObjectStorageKey(file.filename),
|
2021-08-17 02:26:20 -04:00
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-04 04:03:17 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-11-18 08:35:08 -05:00
|
|
|
function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
|
|
|
|
return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
2022-07-25 04:57:16 -04:00
|
|
|
function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) {
|
|
|
|
return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
|
|
|
}
|
|
|
|
|
2022-10-04 04:03:17 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
|
|
|
|
return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
|
|
|
|
}
|
|
|
|
|
2022-10-04 04:03:17 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-11-18 08:35:08 -05:00
|
|
|
async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
|
|
|
|
const key = generateHLSObjectStorageKey(playlist, filename)
|
2021-08-17 02:26:20 -04: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
|
|
|
|
}
|
|
|
|
|
|
|
|
async function makeWebTorrentFileAvailable (filename: string, destination: string) {
|
|
|
|
const key = generateWebTorrentObjectStorageKey(filename)
|
|
|
|
|
|
|
|
logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags())
|
|
|
|
|
|
|
|
await makeAvailable({
|
|
|
|
key,
|
|
|
|
destination,
|
|
|
|
bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
|
|
|
|
})
|
|
|
|
|
|
|
|
return destination
|
|
|
|
}
|
|
|
|
|
2022-10-04 04:03:17 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
export {
|
2022-10-04 04:03:17 -04:00
|
|
|
listHLSFileKeysOf,
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
storeWebTorrentFile,
|
2022-10-04 04:03:17 -04:00
|
|
|
storeHLSFileFromFilename,
|
|
|
|
storeHLSFileFromPath,
|
2021-08-17 02:26:20 -04:00
|
|
|
|
|
|
|
removeHLSObjectStorage,
|
2022-07-25 04:57:16 -04:00
|
|
|
removeHLSFileObjectStorage,
|
2021-08-17 02:26:20 -04:00
|
|
|
removeWebTorrentObjectStorage,
|
|
|
|
|
|
|
|
makeWebTorrentFileAvailable,
|
|
|
|
makeHLSFileAvailable
|
|
|
|
}
|