]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/p2p-media-loader/segment-validator.ts
Restore line feed for markdown lists support in comments
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / p2p-media-loader / segment-validator.ts
index 8f4922daa040f0ec6e1ec3bc01eba5c8229c3e97..72c32f9e058aa63de5aa79db4cd154a79f3285b8 100644 (file)
@@ -3,18 +3,25 @@ import { basename } from 'path'
 
 function segmentValidatorFactory (segmentsSha256Url: string) {
   const segmentsJSON = fetchSha256Segments(segmentsSha256Url)
+  const regex = /bytes=(\d+)-(\d+)/
 
   return async function segmentValidator (segment: Segment) {
-    const segmentName = basename(segment.url)
+    const filename = basename(segment.url)
+    const captured = regex.exec(segment.range)
 
-    const hashShouldBe = (await segmentsJSON)[segmentName]
+    const range = captured[1] + '-' + captured[2]
+
+    const hashShouldBe = (await segmentsJSON)[filename][range]
     if (hashShouldBe === undefined) {
-      throw new Error(`Unknown segment name ${segmentName} in segment validator`)
+      throw new Error(`Unknown segment name ${filename}/${range} in segment validator`)
     }
 
     const calculatedSha = bufferToEx(await sha256(segment.data))
     if (calculatedSha !== hashShouldBe) {
-      throw new Error(`Hashes does not correspond for segment ${segmentName} (expected: ${hashShouldBe} instead of ${calculatedSha})`)
+      throw new Error(
+        `Hashes does not correspond for segment ${filename}/${range}` +
+        `(expected: ${hashShouldBe} instead of ${calculatedSha})`
+      )
     }
   }
 }