diff options
Diffstat (limited to 'server/controllers/object-storage-proxy.ts')
-rw-r--r-- | server/controllers/object-storage-proxy.ts | 15 |
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' |
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 | } | ||