1 import { join } from 'path'
2 import { logger } from '@server/helpers/logger'
3 import { CONFIG } from '@server/initializers/config'
4 import { MStreamingPlaylist, MVideoFile, MVideoUUID } from '@server/types/models'
5 import { getHLSDirectory } from '../paths'
6 import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys'
7 import { lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared'
9 function storeHLSFile (playlist: MStreamingPlaylist, video: MVideoUUID, filename: string) {
10 const baseHlsDirectory = getHLSDirectory(video)
13 inputPath: join(baseHlsDirectory, filename),
14 objectStorageKey: generateHLSObjectStorageKey(playlist, video, filename),
15 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
19 function storeWebTorrentFile (filename: string) {
21 inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename),
22 objectStorageKey: generateWebTorrentObjectStorageKey(filename),
23 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
27 function removeHLSObjectStorage (playlist: MStreamingPlaylist, video: MVideoUUID) {
28 return removePrefix(generateHLSObjectBaseStorageKey(playlist, video), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
31 function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
32 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
35 async function makeHLSFileAvailable (playlist: MStreamingPlaylist, video: MVideoUUID, filename: string, destination: string) {
36 const key = generateHLSObjectStorageKey(playlist, video, filename)
38 logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags())
43 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
49 async function makeWebTorrentFileAvailable (filename: string, destination: string) {
50 const key = generateWebTorrentObjectStorageKey(filename)
52 logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags())
57 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
67 removeHLSObjectStorage,
68 removeWebTorrentObjectStorage,
70 makeWebTorrentFileAvailable,