aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/object-storage-proxy.ts2
-rw-r--r--server/controllers/shared/m3u8-playlist.ts8
-rw-r--r--server/controllers/static.ts3
-rw-r--r--server/tests/api/videos/video-static-file-privacy.ts5
-rw-r--r--server/tests/shared/streaming-playlists.ts3
5 files changed, 13 insertions, 8 deletions
diff --git a/server/controllers/object-storage-proxy.ts b/server/controllers/object-storage-proxy.ts
index 32b8d21da..6bff05f14 100644
--- a/server/controllers/object-storage-proxy.ts
+++ b/server/controllers/object-storage-proxy.ts
@@ -77,7 +77,7 @@ async function proxifyHLS (req: express.Request, res: express.Response) {
77 setS3Headers(res, s3Response) 77 setS3Headers(res, s3Response)
78 78
79 const streamReplacer = filename.endsWith('.m3u8') && doReinjectVideoFileToken(req) 79 const streamReplacer = filename.endsWith('.m3u8') && doReinjectVideoFileToken(req)
80 ? new StreamReplacer(line => injectQueryToPlaylistUrls(line, buildReinjectVideoFileTokenQuery(req))) 80 ? new StreamReplacer(line => injectQueryToPlaylistUrls(line, buildReinjectVideoFileTokenQuery(req, filename.endsWith('master.m3u8'))))
81 : new PassThrough() 81 : new PassThrough()
82 82
83 return pipeline( 83 return pipeline(
diff --git a/server/controllers/shared/m3u8-playlist.ts b/server/controllers/shared/m3u8-playlist.ts
index e2a66efc0..cea5eb5d2 100644
--- a/server/controllers/shared/m3u8-playlist.ts
+++ b/server/controllers/shared/m3u8-playlist.ts
@@ -4,8 +4,12 @@ function doReinjectVideoFileToken (req: express.Request) {
4 return req.query.videoFileToken && req.query.reinjectVideoFileToken 4 return req.query.videoFileToken && req.query.reinjectVideoFileToken
5} 5}
6 6
7function buildReinjectVideoFileTokenQuery (req: express.Request) { 7function buildReinjectVideoFileTokenQuery (req: express.Request, isMaster: boolean) {
8 return 'videoFileToken=' + req.query.videoFileToken 8 const query = 'videoFileToken=' + req.query.videoFileToken
9 if (isMaster) {
10 return query + '&reinjectVideoFileToken=true'
11 }
12 return query
9} 13}
10 14
11export { 15export {
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 52e48267f..9baff94c0 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -90,6 +90,7 @@ export {
90 90
91async function servePrivateM3U8 (req: express.Request, res: express.Response) { 91async function servePrivateM3U8 (req: express.Request, res: express.Response) {
92 const path = join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, req.params.videoUUID, req.params.playlistName + '.m3u8') 92 const path = join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, req.params.videoUUID, req.params.playlistName + '.m3u8')
93 const filename = req.params.playlistName + '.m3u8'
93 94
94 let playlistContent: string 95 let playlistContent: string
95 96
@@ -108,7 +109,7 @@ async function servePrivateM3U8 (req: express.Request, res: express.Response) {
108 109
109 // Inject token in playlist so players that cannot alter the HTTP request can still watch the video 110 // Inject token in playlist so players that cannot alter the HTTP request can still watch the video
110 const transformedContent = doReinjectVideoFileToken(req) 111 const transformedContent = doReinjectVideoFileToken(req)
111 ? injectQueryToPlaylistUrls(playlistContent, buildReinjectVideoFileTokenQuery(req)) 112 ? injectQueryToPlaylistUrls(playlistContent, buildReinjectVideoFileTokenQuery(req, filename.endsWith('master.m3u8')))
112 : playlistContent 113 : playlistContent
113 114
114 return res.set('content-type', 'application/vnd.apple.mpegurl').send(transformedContent).end() 115 return res.set('content-type', 'application/vnd.apple.mpegurl').send(transformedContent).end()
diff --git a/server/tests/api/videos/video-static-file-privacy.ts b/server/tests/api/videos/video-static-file-privacy.ts
index ef0774b41..16530884e 100644
--- a/server/tests/api/videos/video-static-file-privacy.ts
+++ b/server/tests/api/videos/video-static-file-privacy.ts
@@ -256,10 +256,9 @@ describe('Test video static file privacy', function () {
256 const videoFileToken = await server.videoToken.getVideoFileToken({ videoId: uuid }) 256 const videoFileToken = await server.videoToken.getVideoFileToken({ videoId: uuid })
257 await waitJobs([ server ]) 257 await waitJobs([ server ])
258 258
259 const video = await server.videos.getWithToken({ id: uuid })
260 const hls = video.streamingPlaylists[0]
261
262 { 259 {
260 const video = await server.videos.getWithToken({ id: uuid })
261 const hls = video.streamingPlaylists[0]
263 const query = { videoFileToken } 262 const query = { videoFileToken }
264 const { text } = await makeRawRequest({ url: hls.playlistUrl, query, expectedStatus: HttpStatusCode.OK_200 }) 263 const { text } = await makeRawRequest({ url: hls.playlistUrl, query, expectedStatus: HttpStatusCode.OK_200 })
265 264
diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts
index 75e135c4e..1c38cb512 100644
--- a/server/tests/shared/streaming-playlists.ts
+++ b/server/tests/shared/streaming-playlists.ts
@@ -214,7 +214,7 @@ async function checkVideoFileTokenReinjection (options: {
214 ? i 214 ? i
215 : `-${resolution}` 215 : `-${resolution}`
216 216
217 expect(text).to.contain(`${suffix}.m3u8?videoFileToken=${videoFileToken}`) 217 expect(text).to.contain(`${suffix}.m3u8?videoFileToken=${videoFileToken}&reinjectVideoFileToken=true`)
218 } 218 }
219 219
220 const resolutionPlaylists = extractResolutionPlaylistUrls(hls.playlistUrl, text) 220 const resolutionPlaylists = extractResolutionPlaylistUrls(hls.playlistUrl, text)
@@ -228,6 +228,7 @@ async function checkVideoFileTokenReinjection (options: {
228 : '.mp4' 228 : '.mp4'
229 229
230 expect(text).to.contain(`${extension}?videoFileToken=${videoFileToken}`) 230 expect(text).to.contain(`${extension}?videoFileToken=${videoFileToken}`)
231 expect(text).not.to.contain(`reinjectVideoFileToken=true`)
231 } 232 }
232} 233}
233 234