]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/object-storage/videos.ts
Live supports object storage
[github/Chocobozzz/PeerTube.git] / server / lib / object-storage / videos.ts
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'
8
9 function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
10 return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
11 }
12
13 // ---------------------------------------------------------------------------
14
15 function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) {
16 return storeObject({
17 inputPath: join(getHLSDirectory(playlist.Video), filename),
18 objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
19 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
20 })
21 }
22
23 function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) {
24 return storeObject({
25 inputPath: path,
26 objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)),
27 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
28 })
29 }
30
31 // ---------------------------------------------------------------------------
32
33 function storeWebTorrentFile (filename: string) {
34 return storeObject({
35 inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename),
36 objectStorageKey: generateWebTorrentObjectStorageKey(filename),
37 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
38 })
39 }
40
41 // ---------------------------------------------------------------------------
42
43 function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
44 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
45 }
46
47 function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) {
48 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
49 }
50
51 // ---------------------------------------------------------------------------
52
53 function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
54 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
55 }
56
57 // ---------------------------------------------------------------------------
58
59 async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
60 const key = generateHLSObjectStorageKey(playlist, filename)
61
62 logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags())
63
64 await makeAvailable({
65 key,
66 destination,
67 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
68 })
69
70 return destination
71 }
72
73 async function makeWebTorrentFileAvailable (filename: string, destination: string) {
74 const key = generateWebTorrentObjectStorageKey(filename)
75
76 logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags())
77
78 await makeAvailable({
79 key,
80 destination,
81 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
82 })
83
84 return destination
85 }
86
87 // ---------------------------------------------------------------------------
88
89 export {
90 listHLSFileKeysOf,
91
92 storeWebTorrentFile,
93 storeHLSFileFromFilename,
94 storeHLSFileFromPath,
95
96 removeHLSObjectStorage,
97 removeHLSFileObjectStorage,
98 removeWebTorrentObjectStorage,
99
100 makeWebTorrentFileAvailable,
101 makeHLSFileAvailable
102 }