1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

More robust checkLiveSegmentHash

This commit is contained in:
Chocobozzz 2025-07-28 09:46:56 +02:00
parent 121d9029b9
commit 06d9c7a13d
No known key found for this signature in database
GPG key ID: 583A612D890159BE

View file

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { getHLS, removeFragmentedMP4Ext, uuidRegex } from '@peertube/peertube-core-utils' import { getHLS, removeFragmentedMP4Ext, uuidRegex, wait } from '@peertube/peertube-core-utils'
import { import {
FileStorage, FileStorage,
HttpStatusCode, HttpStatusCode,
@ -61,14 +61,28 @@ export async function checkLiveSegmentHash (options: {
segmentName: string segmentName: string
hlsPlaylist: VideoStreamingPlaylist hlsPlaylist: VideoStreamingPlaylist
withRetry?: boolean withRetry?: boolean
currentRetry?: number
}) { }) {
const { server, baseUrlSegment, videoUUID, segmentName, hlsPlaylist, withRetry = false } = options const { server, baseUrlSegment, videoUUID, segmentName, hlsPlaylist, withRetry = false, currentRetry = 1 } = options
const command = server.streamingPlaylists const command = server.streamingPlaylists
const segmentBody = await command.getFragmentedSegment({ url: `${baseUrlSegment}/${videoUUID}/${segmentName}`, withRetry }) try {
const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry }) const segmentBody = await command.getFragmentedSegment({ url: `${baseUrlSegment}/${videoUUID}/${segmentName}`, withRetry: false })
const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: false })
expect(sha256(segmentBody)).to.equal(shaBody[segmentName]) expect(sha256(segmentBody)).to.equal(shaBody[segmentName])
} catch (err) {
if (!withRetry || currentRetry > 10) throw err
await wait(250)
return this.checkLiveSegmentHash({
...options,
withRetry,
currentRetry: currentRetry + 1
})
}
} }
export async function checkPlaylistInfohash (options: { export async function checkPlaylistInfohash (options: {