diff options
author | Chocobozzz <me@florianbigard.com> | 2022-12-19 16:06:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-12-19 16:08:00 +0100 |
commit | 57e11a20f12c69927e5739ecf541ed340934ff90 (patch) | |
tree | 33cefbf0286f0a8d7c4d59f246f364fbd0b52ebd /server | |
parent | 28a398d6d7c178a54aeb5ff45c02daf64fec3e4e (diff) | |
download | PeerTube-57e11a20f12c69927e5739ecf541ed340934ff90.tar.gz PeerTube-57e11a20f12c69927e5739ecf541ed340934ff90.tar.zst PeerTube-57e11a20f12c69927e5739ecf541ed340934ff90.zip |
Forward 206 status code for object storage proxy
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 | // --------------------------------------------------------------------------- |