]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/object-storage/videos.ts
Use private ACL for private videos in s3
[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'
3545e72c 4import { MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/types/models'
0305db28 5import { getHLSDirectory } from '../paths'
3545e72c 6import { VideoPathManager } from '../video-path-manager'
0305db28 7import { generateHLSObjectBaseStorageKey, generateHLSObjectStorageKey, generateWebTorrentObjectStorageKey } from './keys'
9ab330b9
C
8import {
9 createObjectReadStream,
10 listKeysOfPrefix,
11 lTags,
12 makeAvailable,
13 removeObject,
14 removePrefix,
15 storeObject,
16 updateObjectACL,
17 updatePrefixACL
18} from './shared'
0305db28 19
cfd57d2c
C
20function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
21 return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
22}
23
24// ---------------------------------------------------------------------------
25
26function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, filename: string) {
0305db28 27 return storeObject({
cfd57d2c 28 inputPath: join(getHLSDirectory(playlist.Video), filename),
ad5db104 29 objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
9ab330b9
C
30 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
31 isPrivate: playlist.Video.hasPrivateStaticPath()
0305db28
JB
32 })
33}
34
cfd57d2c
C
35function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) {
36 return storeObject({
37 inputPath: path,
38 objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)),
9ab330b9
C
39 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
40 isPrivate: playlist.Video.hasPrivateStaticPath()
cfd57d2c
C
41 })
42}
43
44// ---------------------------------------------------------------------------
45
3545e72c 46function storeWebTorrentFile (video: MVideo, file: MVideoFile) {
0305db28 47 return storeObject({
3545e72c
C
48 inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file),
49 objectStorageKey: generateWebTorrentObjectStorageKey(file.filename),
9ab330b9
C
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()
0305db28
JB
70 })
71}
72
cfd57d2c
C
73// ---------------------------------------------------------------------------
74
ad5db104
C
75function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
76 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
0305db28
JB
77}
78
7b6b445d
C
79function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) {
80 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
81}
82
cfd57d2c
C
83// ---------------------------------------------------------------------------
84
0305db28
JB
85function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
86 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
87}
88
cfd57d2c
C
89// ---------------------------------------------------------------------------
90
ad5db104
C
91async function makeHLSFileAvailable (playlist: MStreamingPlaylistVideo, filename: string, destination: string) {
92 const key = generateHLSObjectStorageKey(playlist, filename)
0305db28
JB
93
94 logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags())
95
96 await makeAvailable({
97 key,
98 destination,
99 bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
100 })
101
102 return destination
103}
104
105async function makeWebTorrentFileAvailable (filename: string, destination: string) {
106 const key = generateWebTorrentObjectStorageKey(filename)
107
108 logger.info('Fetching WebTorrent file %s from object storage to %s.', key, destination, lTags())
109
110 await makeAvailable({
111 key,
112 destination,
113 bucketInfo: CONFIG.OBJECT_STORAGE.VIDEOS
114 })
115
116 return destination
117}
118
cfd57d2c
C
119// ---------------------------------------------------------------------------
120
9ab330b9
C
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
0305db28 154export {
cfd57d2c
C
155 listHLSFileKeysOf,
156
0305db28 157 storeWebTorrentFile,
cfd57d2c
C
158 storeHLSFileFromFilename,
159 storeHLSFileFromPath,
0305db28 160
9ab330b9
C
161 updateWebTorrentFileACL,
162 updateHLSFilesACL,
163
0305db28 164 removeHLSObjectStorage,
7b6b445d 165 removeHLSFileObjectStorage,
0305db28
JB
166 removeWebTorrentObjectStorage,
167
168 makeWebTorrentFileAvailable,
9ab330b9
C
169 makeHLSFileAvailable,
170
171 getWebTorrentFileReadStream,
172 getHLSFileReadStream
0305db28 173}