]>
Commit | Line | Data |
---|---|---|
cfd57d2c | 1 | import { basename, join } from 'path' |
0305db28 JB |
2 | import { logger } from '@server/helpers/logger' |
3 | import { CONFIG } from '@server/initializers/config' | |
3545e72c | 4 | import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/models' |
0305db28 | 5 | import { getHLSDirectory } from '../paths' |
3545e72c | 6 | import { VideoPathManager } from '../video-path-manager' |
0305db28 | 7 | import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' |
9ab330b9 C |
8 | import { |
9 | createObjectReadStream, | |
10 | listKeysOfPrefix, | |
11 | lTags, | |
12 | makeAvailable, | |
13 | removeObject, | |
aa887096 | 14 | removeObjectByFullKey, |
9ab330b9 C |
15 | removePrefix, |
16 | storeObject, | |
17 | updateObjectACL, | |
18 | updatePrefixACL | |
19 | } from './shared' | |
0305db28 | 20 | |
cfd57d2c C |
21 | function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) { |
22 | return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | |
23 | } | |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | ||
27 | function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) { | |
0305db28 | 28 | return storeObject({ |
cfd57d2c | 29 | inputPath: join(getHLSDirectory(playlist.Video), filename), |
ad5db104 | 30 | objectStorageKey: generateHLSObjectStorageKey(playlist, filename), |
9ab330b9 C |
31 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, |
32 | isPrivate: playlist.Video.hasPrivateStaticPath() | |
0305db28 JB |
33 | }) |
34 | } | |
35 | ||
cfd57d2c C |
36 | function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) { |
37 | return storeObject({ | |
38 | inputPath: path, | |
39 | objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)), | |
9ab330b9 C |
40 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, |
41 | isPrivate: playlist.Video.hasPrivateStaticPath() | |
cfd57d2c C |
42 | }) |
43 | } | |
44 | ||
45 | // --------------------------------------------------------------------------- | |
46 | ||
3545e72c | 47 | function storeWebTorrentFile (video: MVideo, file: MVideoFile) { |
0305db28 | 48 | return storeObject({ |
3545e72c C |
49 | inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file), |
50 | objectStorageKey: generateWebTorrentObjectStorageKey(file.filename), | |
9ab330b9 C |
51 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS, |
52 | isPrivate: video.hasPrivateStaticPath() | |
53 | }) | |
54 | } | |
55 | ||
56 | // --------------------------------------------------------------------------- | |
57 | ||
58 | function updateWebTorrentFileACL (video: MVideo, file: MVideoFile) { | |
59 | return updateObjectACL({ | |
60 | objectStorageKey: generateWebTorrentObjectStorageKey(file.filename), | |
61 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS, | |
62 | isPrivate: video.hasPrivateStaticPath() | |
63 | }) | |
64 | } | |
65 | ||
66 | function updateHLSFilesACL (playlist: MStreamingPlaylistVideo) { | |
67 | return updatePrefixACL({ | |
68 | prefix: generateHLSObjectBaseStorageKey(playlist), | |
69 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, | |
70 | isPrivate: playlist.Video.hasPrivateStaticPath() | |
0305db28 JB |
71 | }) |
72 | } | |
73 | ||
cfd57d2c C |
74 | // --------------------------------------------------------------------------- |
75 | ||
ad5db104 C |
76 | function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) { |
77 | return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | |
0305db28 JB |
78 | } |
79 | ||
aa887096 | 80 | function removeHLSFileObjectStorageByFilename (playlist: MStreamingPlaylistVideo, filename: string) { |
7b6b445d C |
81 | return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) |
82 | } | |
83 | ||
aa887096 C |
84 | function removeHLSFileObjectStorageByPath (playlist: MStreamingPlaylistVideo, path: string) { |
85 | return removeObject(generateHLSObjectStorageKey(playlist, basename(path)), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | |
86 | } | |
87 | ||
88 | function removeHLSFileObjectStorageByFullKey (key: string) { | |
89 | return removeObjectByFullKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | |
90 | } | |
91 | ||
cfd57d2c C |
92 | // --------------------------------------------------------------------------- |
93 | ||
0305db28 JB |
94 | function removeWebTorrentObjectStorage (videoFile: MVideoFile) { |
95 | return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS) | |
96 | } | |
97 | ||
cfd57d2c C |
98 | // --------------------------------------------------------------------------- |
99 | ||
ad5db104 C |
100 | async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) { |
101 | const key = generateHLSObjectStorageKey(playlist, filename) | |
0305db28 JB |
102 | |
103 | logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags()) | |
104 | ||
105 | await makeAvailable({ | |
106 | key, | |
107 | destination, | |
108 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS | |
109 | }) | |
110 | ||
111 | return destination | |
112 | } | |
113 | ||
114 | async function makeWebTorrentFileAvailable (filename: string, destination: string) { | |
115 | const key = generateWebTorrentObjectStorageKey(filename) | |
116 | ||
117 | logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags()) | |
118 | ||
119 | await makeAvailable({ | |
120 | key, | |
121 | destination, | |
122 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS | |
123 | }) | |
124 | ||
125 | return destination | |
126 | } | |
127 | ||
cfd57d2c C |
128 | // --------------------------------------------------------------------------- |
129 | ||
9ab330b9 C |
130 | function getWebTorrentFileReadStream (options: { |
131 | filename: string | |
132 | rangeHeader: string | |
133 | }) { | |
134 | const { filename, rangeHeader } = options | |
135 | ||
136 | const key = generateWebTorrentObjectStorageKey(filename) | |
137 | ||
138 | return createObjectReadStream({ | |
139 | key, | |
140 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS, | |
141 | rangeHeader | |
142 | }) | |
143 | } | |
144 | ||
145 | function getHLSFileReadStream (options: { | |
146 | playlist: MStreamingPlaylistVideo | |
147 | filename: string | |
148 | rangeHeader: string | |
149 | }) { | |
150 | const { playlist, filename, rangeHeader } = options | |
151 | ||
152 | const key = generateHLSObjectStorageKey(playlist, filename) | |
153 | ||
154 | return createObjectReadStream({ | |
155 | key, | |
156 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, | |
157 | rangeHeader | |
158 | }) | |
159 | } | |
160 | ||
161 | // --------------------------------------------------------------------------- | |
162 | ||
0305db28 | 163 | export { |
cfd57d2c C |
164 | listHLSFileKeysOf, |
165 | ||
0305db28 | 166 | storeWebTorrentFile, |
cfd57d2c C |
167 | storeHLSFileFromFilename, |
168 | storeHLSFileFromPath, | |
0305db28 | 169 | |
9ab330b9 C |
170 | updateWebTorrentFileACL, |
171 | updateHLSFilesACL, | |
172 | ||
0305db28 | 173 | removeHLSObjectStorage, |
aa887096 C |
174 | removeHLSFileObjectStorageByFilename, |
175 | removeHLSFileObjectStorageByPath, | |
176 | removeHLSFileObjectStorageByFullKey, | |
177 | ||
0305db28 JB |
178 | removeWebTorrentObjectStorage, |
179 | ||
180 | makeWebTorrentFileAvailable, | |
9ab330b9 C |
181 | makeHLSFileAvailable, |
182 | ||
183 | getWebTorrentFileReadStream, | |
184 | getHLSFileReadStream | |
0305db28 | 185 | } |