diff options
Diffstat (limited to 'server/lib/object-storage/videos.ts')
-rw-r--r-- | server/lib/object-storage/videos.ts | 138 |
1 files changed, 124 insertions, 14 deletions
diff --git a/server/lib/object-storage/videos.ts b/server/lib/object-storage/videos.ts index 66e738200..b764e4b22 100644 --- a/server/lib/object-storage/videos.ts +++ b/server/lib/object-storage/videos.ts | |||
@@ -1,39 +1,102 @@ | |||
1 | import { join } from 'path' | 1 | import { basename, join } from 'path' |
2 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
3 | import { CONFIG } from '@server/initializers/config' | 3 | import { CONFIG } from '@server/initializers/config' |
4 | import { MStreamingPlaylistVideo, MVideoFile } from '@server/types/models' | 4 | import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/models' |
5 | import { getHLSDirectory } from '../paths' | 5 | import { getHLSDirectory } from '../paths' |
6 | import { VideoPathManager } from '../video-path-manager' | ||
6 | import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' | 7 | import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' |
7 | import { lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared' | 8 | import { |
9 | createObjectReadStream, | ||
10 | listKeysOfPrefix, | ||
11 | lTags, | ||
12 | makeAvailable, | ||
13 | removeObject, | ||
14 | removeObjectByFullKey, | ||
15 | removePrefix, | ||
16 | storeObject, | ||
17 | updateObjectACL, | ||
18 | updatePrefixACL | ||
19 | } from './shared' | ||
20 | |||
21 | function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) { | ||
22 | return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | ||
23 | } | ||
24 | |||
25 | // --------------------------------------------------------------------------- | ||
8 | 26 | ||
9 | function storeHLSFile (playlist: MStreamingPlaylistVideo, filename: string, path?: string) { | 27 | function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) { |
10 | return storeObject({ | 28 | return storeObject({ |
11 | inputPath: path ?? join(getHLSDirectory(playlist.Video), filename), | 29 | inputPath: join(getHLSDirectory(playlist.Video), filename), |
12 | objectStorageKey: generateHLSObjectStorageKey(playlist, filename), | 30 | objectStorageKey: generateHLSObjectStorageKey(playlist, filename), |
13 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS | 31 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, |
32 | isPrivate: playlist.Video.hasPrivateStaticPath() | ||
14 | }) | 33 | }) |
15 | } | 34 | } |
16 | 35 | ||
17 | function storeWebTorrentFile (filename: string) { | 36 | function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) { |
18 | return storeObject({ | 37 | return storeObject({ |
19 | inputPath: join(CONFIG.STORAGE.VIDEOS_DIR, filename), | 38 | inputPath: path, |
20 | objectStorageKey: generateWebTorrentObjectStorageKey(filename), | 39 | objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)), |
21 | bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS | 40 | bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS, |
41 | isPrivate: playlist.Video.hasPrivateStaticPath() | ||
42 | }) | ||
43 | } | ||
44 | |||
45 | // --------------------------------------------------------------------------- | ||
46 | |||
47 | function storeWebTorrentFile (video: MVideo, file: MVideoFile) { | ||
48 | return storeObject({ | ||
49 | inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file), | ||
50 | objectStorageKey: generateWebTorrentObjectStorageKey(file.filename), | ||
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() | ||
22 | }) | 71 | }) |
23 | } | 72 | } |
24 | 73 | ||
74 | // --------------------------------------------------------------------------- | ||
75 | |||
25 | function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) { | 76 | function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) { |
26 | return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | 77 | return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) |
27 | } | 78 | } |
28 | 79 | ||
29 | function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) { | 80 | function removeHLSFileObjectStorageByFilename (playlist: MStreamingPlaylistVideo, filename: string) { |
30 | return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) | 81 | return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) |
31 | } | 82 | } |
32 | 83 | ||
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 | |||
92 | // --------------------------------------------------------------------------- | ||
93 | |||
33 | function removeWebTorrentObjectStorage (videoFile: MVideoFile) { | 94 | function removeWebTorrentObjectStorage (videoFile: MVideoFile) { |
34 | return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS) | 95 | return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS) |
35 | } | 96 | } |
36 | 97 | ||
98 | // --------------------------------------------------------------------------- | ||
99 | |||
37 | async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) { | 100 | async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) { |
38 | const key = generateHLSObjectStorageKey(playlist, filename) | 101 | const key = generateHLSObjectStorageKey(playlist, filename) |
39 | 102 | ||
@@ -62,14 +125,61 @@ async function makeWebTorrentFileAvailable (filename: string, destination: strin | |||
62 | return destination | 125 | return destination |
63 | } | 126 | } |
64 | 127 | ||
128 | // --------------------------------------------------------------------------- | ||
129 | |||
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 | |||
65 | export { | 163 | export { |
164 | listHLSFileKeysOf, | ||
165 | |||
66 | storeWebTorrentFile, | 166 | storeWebTorrentFile, |
67 | storeHLSFile, | 167 | storeHLSFileFromFilename, |
168 | storeHLSFileFromPath, | ||
169 | |||
170 | updateWebTorrentFileACL, | ||
171 | updateHLSFilesACL, | ||
68 | 172 | ||
69 | removeHLSObjectStorage, | 173 | removeHLSObjectStorage, |
70 | removeHLSFileObjectStorage, | 174 | removeHLSFileObjectStorageByFilename, |
175 | removeHLSFileObjectStorageByPath, | ||
176 | removeHLSFileObjectStorageByFullKey, | ||
177 | |||
71 | removeWebTorrentObjectStorage, | 178 | removeWebTorrentObjectStorage, |
72 | 179 | ||
73 | makeWebTorrentFileAvailable, | 180 | makeWebTorrentFileAvailable, |
74 | makeHLSFileAvailable | 181 | makeHLSFileAvailable, |
182 | |||
183 | getWebTorrentFileReadStream, | ||
184 | getHLSFileReadStream | ||
75 | } | 185 | } |