diff options
Diffstat (limited to 'server/lib/object-storage/videos.ts')
-rw-r--r-- | server/lib/object-storage/videos.ts | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/server/lib/object-storage/videos.ts b/server/lib/object-storage/videos.ts deleted file mode 100644 index 891e9ff76..000000000 --- a/server/lib/object-storage/videos.ts +++ /dev/null | |||
@@ -1,197 +0,0 @@ | |||
1 | import { basename, join } from 'path' | ||
2 | import { logger } from '@server/helpers/logger' | ||
3 | import { CONFIG } from '@server/initializers/config' | ||
4 | import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/models' | ||
5 | import { getHLSDirectory } from '../paths' | ||
6 | import { VideoPathManager } from '../video-path-manager' | ||
7 | import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebVideoObjectStorageKey } from './keys' | ||
8 | import { | ||
9 | createObjectReadStream, | ||
10 | listKeysOfPrefix, | ||
11 | lTags, | ||
12 | makeAvailable, | ||
13 | removeObject, | ||
14 | removeObjectByFullKey, | ||
15 | removePrefix, | ||
16 | storeContent, | ||
17 | storeObject, | ||
18 | updateObjectACL, | ||
19 | updatePrefixACL | ||
20 | } from './shared' | ||
21 | |||
22 | function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) { | ||
23 | return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | ||
24 | } | ||
25 | |||
26 | // --------------------------------------------------------------------------- | ||
27 | |||
28 | function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) { | ||
29 | return storeObject({ | ||
30 | inputPath: join(getHLSDirectory(playlist.Video), filename), | ||
31 | objectStorageKey: generateHLSObjectStorageKey(playlist, filename), | ||
32 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, | ||
33 | isPrivate: playlist.Video.hasPrivateStaticPath() | ||
34 | }) | ||
35 | } | ||
36 | |||
37 | function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) { | ||
38 | return storeObject({ | ||
39 | inputPath: path, | ||
40 | objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)), | ||
41 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, | ||
42 | isPrivate: playlist.Video.hasPrivateStaticPath() | ||
43 | }) | ||
44 | } | ||
45 | |||
46 | function storeHLSFileFromContent (playlist: MStreamingPlaylistVideo, path: string, content: string) { | ||
47 | return storeContent({ | ||
48 | content, | ||
49 | inputPath: path, | ||
50 | objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)), | ||
51 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, | ||
52 | isPrivate: playlist.Video.hasPrivateStaticPath() | ||
53 | }) | ||
54 | } | ||
55 | |||
56 | // --------------------------------------------------------------------------- | ||
57 | |||
58 | function storeWebVideoFile (video: MVideo, file: MVideoFile) { | ||
59 | return storeObject({ | ||
60 | inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file), | ||
61 | objectStorageKey: generateWebVideoObjectStorageKey(file.filename), | ||
62 | bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS, | ||
63 | isPrivate: video.hasPrivateStaticPath() | ||
64 | }) | ||
65 | } | ||
66 | |||
67 | // --------------------------------------------------------------------------- | ||
68 | |||
69 | async function updateWebVideoFileACL (video: MVideo, file: MVideoFile) { | ||
70 | await updateObjectACL({ | ||
71 | objectStorageKey: generateWebVideoObjectStorageKey(file.filename), | ||
72 | bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS, | ||
73 | isPrivate: video.hasPrivateStaticPath() | ||
74 | }) | ||
75 | } | ||
76 | |||
77 | async function updateHLSFilesACL (playlist: MStreamingPlaylistVideo) { | ||
78 | await updatePrefixACL({ | ||
79 | prefix: generateHLSObjectBaseStorageKey(playlist), | ||
80 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, | ||
81 | isPrivate: playlist.Video.hasPrivateStaticPath() | ||
82 | }) | ||
83 | } | ||
84 | |||
85 | // --------------------------------------------------------------------------- | ||
86 | |||
87 | function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) { | ||
88 | return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | ||
89 | } | ||
90 | |||
91 | function removeHLSFileObjectStorageByFilename (playlist: MStreamingPlaylistVideo, filename: string) { | ||
92 | return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | ||
93 | } | ||
94 | |||
95 | function removeHLSFileObjectStorageByPath (playlist: MStreamingPlaylistVideo, path: string) { | ||
96 | return removeObject(generateHLSObjectStorageKey(playlist, basename(path)), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | ||
97 | } | ||
98 | |||
99 | function removeHLSFileObjectStorageByFullKey (key: string) { | ||
100 | return removeObjectByFullKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | ||
101 | } | ||
102 | |||
103 | // --------------------------------------------------------------------------- | ||
104 | |||
105 | function removeWebVideoObjectStorage (videoFile: MVideoFile) { | ||
106 | return removeObject(generateWebVideoObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.WEB_VIDEOS) | ||
107 | } | ||
108 | |||
109 | // --------------------------------------------------------------------------- | ||
110 | |||
111 | async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) { | ||
112 | const key = generateHLSObjectStorageKey(playlist, filename) | ||
113 | |||
114 | logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags()) | ||
115 | |||
116 | await makeAvailable({ | ||
117 | key, | ||
118 | destination, | ||
119 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS | ||
120 | }) | ||
121 | |||
122 | return destination | ||
123 | } | ||
124 | |||
125 | async function makeWebVideoFileAvailable (filename: string, destination: string) { | ||
126 | const key = generateWebVideoObjectStorageKey(filename) | ||
127 | |||
128 | logger.info('Fetching Web Video file %s from object storage to %s.', key, destination, lTags()) | ||
129 | |||
130 | await makeAvailable({ | ||
131 | key, | ||
132 | destination, | ||
133 | bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS | ||
134 | }) | ||
135 | |||
136 | return destination | ||
137 | } | ||
138 | |||
139 | // --------------------------------------------------------------------------- | ||
140 | |||
141 | function getWebVideoFileReadStream (options: { | ||
142 | filename: string | ||
143 | rangeHeader: string | ||
144 | }) { | ||
145 | const { filename, rangeHeader } = options | ||
146 | |||
147 | const key = generateWebVideoObjectStorageKey(filename) | ||
148 | |||
149 | return createObjectReadStream({ | ||
150 | key, | ||
151 | bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS, | ||
152 | rangeHeader | ||
153 | }) | ||
154 | } | ||
155 | |||
156 | function getHLSFileReadStream (options: { | ||
157 | playlist: MStreamingPlaylistVideo | ||
158 | filename: string | ||
159 | rangeHeader: string | ||
160 | }) { | ||
161 | const { playlist, filename, rangeHeader } = options | ||
162 | |||
163 | const key = generateHLSObjectStorageKey(playlist, filename) | ||
164 | |||
165 | return createObjectReadStream({ | ||
166 | key, | ||
167 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, | ||
168 | rangeHeader | ||
169 | }) | ||
170 | } | ||
171 | |||
172 | // --------------------------------------------------------------------------- | ||
173 | |||
174 | export { | ||
175 | listHLSFileKeysOf, | ||
176 | |||
177 | storeWebVideoFile, | ||
178 | storeHLSFileFromFilename, | ||
179 | storeHLSFileFromPath, | ||
180 | storeHLSFileFromContent, | ||
181 | |||
182 | updateWebVideoFileACL, | ||
183 | updateHLSFilesACL, | ||
184 | |||
185 | removeHLSObjectStorage, | ||
186 | removeHLSFileObjectStorageByFilename, | ||
187 | removeHLSFileObjectStorageByPath, | ||
188 | removeHLSFileObjectStorageByFullKey, | ||
189 | |||
190 | removeWebVideoObjectStorage, | ||
191 | |||
192 | makeWebVideoFileAvailable, | ||
193 | makeHLSFileAvailable, | ||
194 | |||
195 | getWebVideoFileReadStream, | ||
196 | getHLSFileReadStream | ||
197 | } | ||