1 import { 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 { lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared'
9 function storeHLSFile (playlist: MStreamingPlaylistVideo, filename: string, path?: string) {
11 inputPath: path ?? join(getHLSDirectory(playlist.Video), filename),
12 objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
13 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
17 function storeWebTorrentFile (filename: string) {
19 inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename),
20 objectStorageKey: generateWebTorrentObjectStorageKey(filename),
21 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
25 function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
26 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
29 function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) {
30 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
33 function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
34 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
37 async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
38 const key = generateHLSObjectStorageKey(playlist, filename)
40 logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags())
45 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
51 async function makeWebTorrentFileAvailable (filename: string, destination: string) {
52 const key = generateWebTorrentObjectStorageKey(filename)
54 logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags())
59 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
69 removeHLSObjectStorage,
70 removeHLSFileObjectStorage,
71 removeWebTorrentObjectStorage,
73 makeWebTorrentFileAvailable,