aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/object-storage-proxy.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-12-19 16:06:58 +0100
committerChocobozzz <me@florianbigard.com>2022-12-19 16:08:00 +0100
commit57e11a20f12c69927e5739ecf541ed340934ff90 (patch)
tree33cefbf0286f0a8d7c4d59f246f364fbd0b52ebd /server/controllers/object-storage-proxy.ts
parent28a398d6d7c178a54aeb5ff45c02daf64fec3e4e (diff)
downloadPeerTube-57e11a20f12c69927e5739ecf541ed340934ff90.tar.gz
PeerTube-57e11a20f12c69927e5739ecf541ed340934ff90.tar.zst
PeerTube-57e11a20f12c69927e5739ecf541ed340934ff90.zip
Forward 206 status code for object storage proxy
Diffstat (limited to 'server/controllers/object-storage-proxy.ts')
-rw-r--r--server/controllers/object-storage-proxy.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/server/controllers/object-storage-proxy.ts b/server/controllers/object-storage-proxy.ts
index aa853a383..32b8d21da 100644
--- a/server/controllers/object-storage-proxy.ts
+++ b/server/controllers/object-storage-proxy.ts
@@ -15,6 +15,7 @@ import {
15} from '@server/middlewares' 15} from '@server/middlewares'
16import { HttpStatusCode } from '@shared/models' 16import { HttpStatusCode } from '@shared/models'
17import { buildReinjectVideoFileTokenQuery, doReinjectVideoFileToken } from './shared/m3u8-playlist' 17import { buildReinjectVideoFileTokenQuery, doReinjectVideoFileToken } from './shared/m3u8-playlist'
18import { GetObjectCommandOutput } from '@aws-sdk/client-s3'
18 19
19const objectStorageProxyRouter = express.Router() 20const objectStorageProxyRouter = express.Router()
20 21
@@ -46,11 +47,13 @@ async function proxifyWebTorrent (req: express.Request, res: express.Response) {
46 logger.debug('Proxifying WebTorrent file %s from object storage.', filename) 47 logger.debug('Proxifying WebTorrent file %s from object storage.', filename)
47 48
48 try { 49 try {
49 const stream = await getWebTorrentFileReadStream({ 50 const { response: s3Response, stream } = await getWebTorrentFileReadStream({
50 filename, 51 filename,
51 rangeHeader: req.header('range') 52 rangeHeader: req.header('range')
52 }) 53 })
53 54
55 setS3Headers(res, s3Response)
56
54 return stream.pipe(res) 57 return stream.pipe(res)
55 } catch (err) { 58 } catch (err) {
56 return handleObjectStorageFailure(res, err) 59 return handleObjectStorageFailure(res, err)
@@ -65,12 +68,14 @@ async function proxifyHLS (req: express.Request, res: express.Response) {
65 logger.debug('Proxifying HLS file %s from object storage.', filename) 68 logger.debug('Proxifying HLS file %s from object storage.', filename)
66 69
67 try { 70 try {
68 const stream = await getHLSFileReadStream({ 71 const { response: s3Response, stream } = await getHLSFileReadStream({
69 playlist: playlist.withVideo(video), 72 playlist: playlist.withVideo(video),
70 filename, 73 filename,
71 rangeHeader: req.header('range') 74 rangeHeader: req.header('range')
72 }) 75 })
73 76
77 setS3Headers(res, s3Response)
78
74 const streamReplacer = filename.endsWith('.m3u8') && doReinjectVideoFileToken(req) 79 const streamReplacer = filename.endsWith('.m3u8') && doReinjectVideoFileToken(req)
75 ? new StreamReplacer(line => injectQueryToPlaylistUrls(line, buildReinjectVideoFileTokenQuery(req))) 80 ? new StreamReplacer(line => injectQueryToPlaylistUrls(line, buildReinjectVideoFileTokenQuery(req)))
76 : new PassThrough() 81 : new PassThrough()
@@ -102,3 +107,9 @@ function handleObjectStorageFailure (res: express.Response, err: Error) {
102 type: err.name 107 type: err.name
103 }) 108 })
104} 109}
110
111function setS3Headers (res: express.Response, s3Response: GetObjectCommandOutput) {
112 if (s3Response.$metadata.httpStatusCode === HttpStatusCode.PARTIAL_CONTENT_206) {
113 res.status(HttpStatusCode.PARTIAL_CONTENT_206)
114 }
115}