aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/p2p-media-loader
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-07 15:08:19 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-02-11 09:13:02 +0100
commit4c280004ce62bf11ddb091854c28f1e1d54a54d6 (patch)
tree1899fff4ef18f8663a865997d5d06119b2149319 /client/src/assets/player/p2p-media-loader
parent6ec0b75beb9c8bcd84e178912319913b91830da2 (diff)
downloadPeerTube-4c280004ce62bf11ddb091854c28f1e1d54a54d6.tar.gz
PeerTube-4c280004ce62bf11ddb091854c28f1e1d54a54d6.tar.zst
PeerTube-4c280004ce62bf11ddb091854c28f1e1d54a54d6.zip
Use a single file instead of segments for HLS
Diffstat (limited to 'client/src/assets/player/p2p-media-loader')
-rw-r--r--client/src/assets/player/p2p-media-loader/segment-validator.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts
index 8f4922daa..72c32f9e0 100644
--- a/client/src/assets/player/p2p-media-loader/segment-validator.ts
+++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts
@@ -3,18 +3,25 @@ import { basename } from 'path'
3 3
4function segmentValidatorFactory (segmentsSha256Url: string) { 4function segmentValidatorFactory (segmentsSha256Url: string) {
5 const segmentsJSON = fetchSha256Segments(segmentsSha256Url) 5 const segmentsJSON = fetchSha256Segments(segmentsSha256Url)
6 const regex = /bytes=(\d+)-(\d+)/
6 7
7 return async function segmentValidator (segment: Segment) { 8 return async function segmentValidator (segment: Segment) {
8 const segmentName = basename(segment.url) 9 const filename = basename(segment.url)
10 const captured = regex.exec(segment.range)
9 11
10 const hashShouldBe = (await segmentsJSON)[segmentName] 12 const range = captured[1] + '-' + captured[2]
13
14 const hashShouldBe = (await segmentsJSON)[filename][range]
11 if (hashShouldBe === undefined) { 15 if (hashShouldBe === undefined) {
12 throw new Error(`Unknown segment name ${segmentName} in segment validator`) 16 throw new Error(`Unknown segment name ${filename}/${range} in segment validator`)
13 } 17 }
14 18
15 const calculatedSha = bufferToEx(await sha256(segment.data)) 19 const calculatedSha = bufferToEx(await sha256(segment.data))
16 if (calculatedSha !== hashShouldBe) { 20 if (calculatedSha !== hashShouldBe) {
17 throw new Error(`Hashes does not correspond for segment ${segmentName} (expected: ${hashShouldBe} instead of ${calculatedSha})`) 21 throw new Error(
22 `Hashes does not correspond for segment ${filename}/${range}` +
23 `(expected: ${hashShouldBe} instead of ${calculatedSha})`
24 )
18 } 25 }
19 } 26 }
20} 27}