1 import { basename, join } from 'path'
2 import { logger } from '@server/helpers/logger'
3 import { CONFIG } from '@server/initializers/config'
4 import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models'
5 import { getHLSDirectory } from '../paths'
6 import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys'
7 import { listKeysOfPrefix, lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared'
9 function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
10 return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
13 // ---------------------------------------------------------------------------
15 function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) {
17 inputPath: join(getHLSDirectory(playlist.Video), filename),
18 objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
19 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
23 function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) {
26 objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)),
27 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
31 // ---------------------------------------------------------------------------
33 function storeWebTorrentFile (filename: string) {
35 inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename),
36 objectStorageKey: generateWebTorrentObjectStorageKey(filename),
37 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
41 // ---------------------------------------------------------------------------
43 function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
44 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
47 function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) {
48 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
51 // ---------------------------------------------------------------------------
53 function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
54 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
57 // ---------------------------------------------------------------------------
59 async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
60 const key = generateHLSObjectStorageKey(playlist, filename)
62 logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags())
67 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
73 async function makeWebTorrentFileAvailable (filename: string, destination: string) {
74 const key = generateWebTorrentObjectStorageKey(filename)
76 logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags())
81 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
87 // ---------------------------------------------------------------------------
93 storeHLSFileFromFilename,
96 removeHLSObjectStorage,
97 removeHLSFileObjectStorage,
98 removeWebTorrentObjectStorage,
100 makeWebTorrentFileAvailable,