diff options
author | Wicklow <wicklow@framasoft.org> | 2023-03-07 10:52:20 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-03-07 11:16:56 +0100 |
commit | 73fb3dc53571a6e94750a9d6cb5c2e949e1adcb9 (patch) | |
tree | f86cfe5b29a999bcbc10562e918df33429b468b4 /server/controllers | |
parent | a3e5f7e732cca41267314d64307bdcfebd12e7de (diff) | |
download | PeerTube-73fb3dc53571a6e94750a9d6cb5c2e949e1adcb9.tar.gz PeerTube-73fb3dc53571a6e94750a9d6cb5c2e949e1adcb9.tar.zst PeerTube-73fb3dc53571a6e94750a9d6cb5c2e949e1adcb9.zip |
Fix file token reinjection on fragments
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/object-storage-proxy.ts | 2 | ||||
-rw-r--r-- | server/controllers/shared/m3u8-playlist.ts | 8 | ||||
-rw-r--r-- | server/controllers/static.ts | 3 |
3 files changed, 9 insertions, 4 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 | ||
7 | function buildReinjectVideoFileTokenQuery (req: express.Request) { | 7 | function 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 | ||
11 | export { | 15 | export { |
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 | ||
91 | async function servePrivateM3U8 (req: express.Request, res: express.Response) { | 91 | async 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() |