]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/object-storage/videos.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / object-storage / videos.ts
CommitLineData
0305db28
JB
1import { join } from 'path'
2import { logger } from '@server/helpers/logger'
3import { CONFIG } from '@server/initializers/config'
ad5db104 4import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models'
0305db28
JB
5import { getHLSDirectory } from '../paths'
6import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys'
7import { lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared'
8
a2caee9f 9function storeHLSFile (playlist: MStreamingPlaylistVideo, filename: string, path?: string) {
0305db28 10 return storeObject({
a2caee9f 11 inputPath: path ?? join(getHLSDirectory(playlist.Video), filename),
ad5db104 12 objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
0305db28
JB
13 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
14 })
15}
16
17function storeWebTorrentFile (filename: string) {
18 return storeObject({
19 inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename),
20 objectStorageKey: generateWebTorrentObjectStorageKey(filename),
21 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
22 })
23}
24
ad5db104
C
25function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
26 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
0305db28
JB
27}
28
7b6b445d
C
29function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) {
30 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
31}
32
0305db28
JB
33function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
34 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
35}
36
ad5db104
C
37async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
38 const key = generateHLSObjectStorageKey(playlist, filename)
0305db28
JB
39
40 logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags())
41
42 await makeAvailable({
43 key,
44 destination,
45 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
46 })
47
48 return destination
49}
50
51async function makeWebTorrentFileAvailable (filename: string, destination: string) {
52 const key = generateWebTorrentObjectStorageKey(filename)
53
54 logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags())
55
56 await makeAvailable({
57 key,
58 destination,
59 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
60 })
61
62 return destination
63}
64
65export {
66 storeWebTorrentFile,
67 storeHLSFile,
68
69 removeHLSObjectStorage,
7b6b445d 70 removeHLSFileObjectStorage,
0305db28
JB
71 removeWebTorrentObjectStorage,
72
73 makeWebTorrentFileAvailable,
74 makeHLSFileAvailable
75}