aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-12-19 16:10:38 +0100
committerChocobozzz <me@florianbigard.com>2022-12-19 16:10:38 +0100
commit93293ca7887e34fd9b6413fdaeea3d1dddc46ece (patch)
tree63272268dde4bfd1dcc9ff46b46d758d25c0b88f /server
parentc6820dc4a58919d381c3bc0bad131ba1d3b10443 (diff)
parent57e11a20f12c69927e5739ecf541ed340934ff90 (diff)
downloadPeerTube-93293ca7887e34fd9b6413fdaeea3d1dddc46ece.tar.gz
PeerTube-93293ca7887e34fd9b6413fdaeea3d1dddc46ece.tar.zst
PeerTube-93293ca7887e34fd9b6413fdaeea3d1dddc46ece.zip
Merge branch 'release/5.0.0' into develop
Diffstat (limited to 'server')
-rw-r--r--server/controllers/object-storage-proxy.ts15
-rw-r--r--server/lib/object-storage/shared/object-storage-helpers.ts5
2 files changed, 17 insertions, 3 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}
diff --git a/server/lib/object-storage/shared/object-storage-helpers.ts b/server/lib/object-storage/shared/object-storage-helpers.ts
index 3046d76bc..8dff08ab4 100644
--- a/server/lib/object-storage/shared/object-storage-helpers.ts
+++ b/server/lib/object-storage/shared/object-storage-helpers.ts
@@ -187,7 +187,10 @@ async function createObjectReadStream (options: {
187 187
188 const response = await getClient().send(command) 188 const response = await getClient().send(command)
189 189
190 return response.Body as Readable 190 return {
191 response,
192 stream: response.Body as Readable
193 }
191} 194}
192 195
193// --------------------------------------------------------------------------- 196// ---------------------------------------------------------------------------