aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/live
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-24 09:34:56 +0200
committerChocobozzz <me@florianbigard.com>2022-06-24 09:35:30 +0200
commitb6e2b5df73d3b67e275000f612907859c39d90d1 (patch)
tree0a95609e1eaeb33d18bf16d6328d25ed69d6d4d6 /server/lib/live
parentf2623febd8b7b818e47d995ae59f4f1d2f37961b (diff)
downloadPeerTube-b6e2b5df73d3b67e275000f612907859c39d90d1.tar.gz
PeerTube-b6e2b5df73d3b67e275000f612907859c39d90d1.tar.zst
PeerTube-b6e2b5df73d3b67e275000f612907859c39d90d1.zip
Fix removed sha segments on fast restream
Diffstat (limited to 'server/lib/live')
-rw-r--r--server/lib/live/live-manager.ts5
-rw-r--r--server/lib/live/live-utils.ts15
2 files changed, 12 insertions, 8 deletions
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts
index f2f064b49..d499b4b1a 100644
--- a/server/lib/live/live-manager.ts
+++ b/server/lib/live/live-manager.ts
@@ -27,7 +27,6 @@ import { JobQueue } from '../job-queue'
27import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths' 27import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths'
28import { PeerTubeSocket } from '../peertube-socket' 28import { PeerTubeSocket } from '../peertube-socket'
29import { LiveQuotaStore } from './live-quota-store' 29import { LiveQuotaStore } from './live-quota-store'
30import { LiveSegmentShaStore } from './live-segment-sha-store'
31import { cleanupPermanentLive } from './live-utils' 30import { cleanupPermanentLive } from './live-utils'
32import { MuxingSession } from './shared' 31import { MuxingSession } from './shared'
33 32
@@ -219,9 +218,7 @@ class LiveManager {
219 return this.abortSession(sessionId) 218 return this.abortSession(sessionId)
220 } 219 }
221 220
222 // Cleanup old potential live files (could happen with a permanent live) 221 // Cleanup old potential live (could happen with a permanent live)
223 LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid)
224
225 const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) 222 const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id)
226 if (oldStreamingPlaylist) { 223 if (oldStreamingPlaylist) {
227 if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid) 224 if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid)
diff --git a/server/lib/live/live-utils.ts b/server/lib/live/live-utils.ts
index 6305a97a8..bba876642 100644
--- a/server/lib/live/live-utils.ts
+++ b/server/lib/live/live-utils.ts
@@ -3,6 +3,7 @@ import { basename, join } from 'path'
3import { logger } from '@server/helpers/logger' 3import { logger } from '@server/helpers/logger'
4import { MStreamingPlaylist, MVideo } from '@server/types/models' 4import { MStreamingPlaylist, MVideo } from '@server/types/models'
5import { getLiveDirectory } from '../paths' 5import { getLiveDirectory } from '../paths'
6import { LiveSegmentShaStore } from './live-segment-sha-store'
6 7
7function buildConcatenatedName (segmentOrPlaylistPath: string) { 8function buildConcatenatedName (segmentOrPlaylistPath: string) {
8 const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/) 9 const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/)
@@ -11,9 +12,7 @@ function buildConcatenatedName (segmentOrPlaylistPath: string) {
11} 12}
12 13
13async function cleanupPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { 14async function cleanupPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
14 const hlsDirectory = getLiveDirectory(video) 15 await cleanupTMPLiveFiles(video)
15
16 await cleanupTMPLiveFiles(hlsDirectory)
17 16
18 await streamingPlaylist.destroy() 17 await streamingPlaylist.destroy()
19} 18}
@@ -24,11 +23,19 @@ async function cleanupUnsavedNormalLive (video: MVideo, streamingPlaylist: MStre
24 await remove(hlsDirectory) 23 await remove(hlsDirectory)
25 24
26 await streamingPlaylist.destroy() 25 await streamingPlaylist.destroy()
26
27 LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid)
27} 28}
28 29
29async function cleanupTMPLiveFiles (hlsDirectory: string) { 30async function cleanupTMPLiveFiles (video: MVideo) {
31 const hlsDirectory = getLiveDirectory(video)
32
33 LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid)
34
30 if (!await pathExists(hlsDirectory)) return 35 if (!await pathExists(hlsDirectory)) return
31 36
37 logger.info('Cleanup TMP live files of %s.', hlsDirectory)
38
32 const files = await readdir(hlsDirectory) 39 const files = await readdir(hlsDirectory)
33 40
34 for (const filename of files) { 41 for (const filename of files) {