]> 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
cfd57d2c 1import { basename, join } from 'path'
0305db28
JB
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'
cfd57d2c 7import { listKeysOfPrefix, lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared'
0305db28 8
cfd57d2c
C
9function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
10 return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
11}
12
13// ---------------------------------------------------------------------------
14
15function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) {
0305db28 16 return storeObject({
cfd57d2c 17 inputPath: join(getHLSDirectory(playlist.Video), filename),
ad5db104 18 objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
0305db28
JB
19 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
20 })
21}
22
cfd57d2c
C
23function 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
0305db28
JB
33function 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
cfd57d2c
C
41// ---------------------------------------------------------------------------
42
ad5db104
C
43function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
44 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
0305db28
JB
45}
46
7b6b445d
C
47function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) {
48 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
49}
50
cfd57d2c
C
51// ---------------------------------------------------------------------------
52
0305db28
JB
53function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
54 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
55}
56
cfd57d2c
C
57// ---------------------------------------------------------------------------
58
ad5db104
C
59async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
60 const key = generateHLSObjectStorageKey(playlist, filename)
0305db28
JB
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
73async 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
cfd57d2c
C
87// ---------------------------------------------------------------------------
88
0305db28 89export {
cfd57d2c
C
90 listHLSFileKeysOf,
91
0305db28 92 storeWebTorrentFile,
cfd57d2c
C
93 storeHLSFileFromFilename,
94 storeHLSFileFromPath,
0305db28
JB
95
96 removeHLSObjectStorage,
7b6b445d 97 removeHLSFileObjectStorage,
0305db28
JB
98 removeWebTorrentObjectStorage,
99
100 makeWebTorrentFileAvailable,
101 makeHLSFileAvailable
102}