diff options
author | Chocobozzz <me@florianbigard.com> | 2022-12-19 16:10:38 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-12-19 16:10:38 +0100 |
commit | 93293ca7887e34fd9b6413fdaeea3d1dddc46ece (patch) | |
tree | 63272268dde4bfd1dcc9ff46b46d758d25c0b88f /server | |
parent | c6820dc4a58919d381c3bc0bad131ba1d3b10443 (diff) | |
parent | 57e11a20f12c69927e5739ecf541ed340934ff90 (diff) | |
download | PeerTube-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.ts | 15 | ||||
-rw-r--r-- | server/lib/object-storage/shared/object-storage-helpers.ts | 5 |
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' |
16 | import { HttpStatusCode } from '@shared/models' | 16 | import { HttpStatusCode } from '@shared/models' |
17 | import { buildReinjectVideoFileTokenQuery, doReinjectVideoFileToken } from './shared/m3u8-playlist' | 17 | import { buildReinjectVideoFileTokenQuery, doReinjectVideoFileToken } from './shared/m3u8-playlist' |
18 | import { GetObjectCommandOutput } from '@aws-sdk/client-s3' | ||
18 | 19 | ||
19 | const objectStorageProxyRouter = express.Router() | 20 | const 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 | |||
111 | function 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 | // --------------------------------------------------------------------------- |