aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/object-storage/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/object-storage/videos.ts')
-rw-r--r--server/lib/object-storage/videos.ts80
1 files changed, 75 insertions, 5 deletions
diff --git a/server/lib/object-storage/videos.ts b/server/lib/object-storage/videos.ts
index e323baaa2..003807826 100644
--- a/server/lib/object-storage/videos.ts
+++ b/server/lib/object-storage/videos.ts
@@ -5,7 +5,17 @@ import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/model
5import { getHLSDirectory } from '../paths' 5import { getHLSDirectory } from '../paths'
6import { VideoPathManager } from '../video-path-manager' 6import { VideoPathManager } from '../video-path-manager'
7import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys' 7import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys'
8import { listKeysOfPrefix, lTags, makeAvailable, removeObject, removePrefix, storeObject } from './shared' 8import {
9 createObjectReadStream,
10 listKeysOfPrefix,
11 lTags,
12 makeAvailable,
13 removeObject,
14 removePrefix,
15 storeObject,
16 updateObjectACL,
17 updatePrefixACL
18} from './shared'
9 19
10function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) { 20function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
11 return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) 21 return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
@@ -17,7 +27,8 @@ function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename:
17 return storeObject({ 27 return storeObject({
18 inputPath: join(getHLSDirectory(playlist.Video), filename), 28 inputPath: join(getHLSDirectory(playlist.Video), filename),
19 objectStorageKey: generateHLSObjectStorageKey(playlist, filename), 29 objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
20 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS 30 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
31 isPrivate: playlist.Video.hasPrivateStaticPath()
21 }) 32 })
22} 33}
23 34
@@ -25,7 +36,8 @@ function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string)
25 return storeObject({ 36 return storeObject({
26 inputPath: path, 37 inputPath: path,
27 objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)), 38 objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)),
28 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS 39 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
40 isPrivate: playlist.Video.hasPrivateStaticPath()
29 }) 41 })
30} 42}
31 43
@@ -35,7 +47,26 @@ function storeWebTorrentFile (video: MVideo, file: MVideoFile) {
35 return storeObject({ 47 return storeObject({
36 inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file), 48 inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file),
37 objectStorageKey: generateWebTorrentObjectStorageKey(file.filename), 49 objectStorageKey: generateWebTorrentObjectStorageKey(file.filename),
38 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS 50 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS,
51 isPrivate: video.hasPrivateStaticPath()
52 })
53}
54
55// ---------------------------------------------------------------------------
56
57function updateWebTorrentFileACL (video: MVideo, file: MVideoFile) {
58 return updateObjectACL({
59 objectStorageKey: generateWebTorrentObjectStorageKey(file.filename),
60 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS,
61 isPrivate: video.hasPrivateStaticPath()
62 })
63}
64
65function updateHLSFilesACL (playlist: MStreamingPlaylistVideo) {
66 return updatePrefixACL({
67 prefix: generateHLSObjectBaseStorageKey(playlist),
68 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
69 isPrivate: playlist.Video.hasPrivateStaticPath()
39 }) 70 })
40} 71}
41 72
@@ -87,6 +118,39 @@ async function makeWebTorrentFileAvailable (filename: string, destination: strin
87 118
88// --------------------------------------------------------------------------- 119// ---------------------------------------------------------------------------
89 120
121function getWebTorrentFileReadStream (options: {
122 filename: string
123 rangeHeader: string
124}) {
125 const { filename, rangeHeader } = options
126
127 const key = generateWebTorrentObjectStorageKey(filename)
128
129 return createObjectReadStream({
130 key,
131 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS,
132 rangeHeader
133 })
134}
135
136function getHLSFileReadStream (options: {
137 playlist: MStreamingPlaylistVideo
138 filename: string
139 rangeHeader: string
140}) {
141 const { playlist, filename, rangeHeader } = options
142
143 const key = generateHLSObjectStorageKey(playlist, filename)
144
145 return createObjectReadStream({
146 key,
147 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
148 rangeHeader
149 })
150}
151
152// ---------------------------------------------------------------------------
153
90export { 154export {
91 listHLSFileKeysOf, 155 listHLSFileKeysOf,
92 156
@@ -94,10 +158,16 @@ export {
94 storeHLSFileFromFilename, 158 storeHLSFileFromFilename,
95 storeHLSFileFromPath, 159 storeHLSFileFromPath,
96 160
161 updateWebTorrentFileACL,
162 updateHLSFilesACL,
163
97 removeHLSObjectStorage, 164 removeHLSObjectStorage,
98 removeHLSFileObjectStorage, 165 removeHLSFileObjectStorage,
99 removeWebTorrentObjectStorage, 166 removeWebTorrentObjectStorage,
100 167
101 makeWebTorrentFileAvailable, 168 makeWebTorrentFileAvailable,
102 makeHLSFileAvailable 169 makeHLSFileAvailable,
170
171 getWebTorrentFileReadStream,
172 getHLSFileReadStream
103} 173}