X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Flive%2Flive-utils.ts;h=bba8766428aa409a9daaff816ac1136d060cd0eb;hb=39d117a47d313637cf3ded4c6fa915aa9fd469ee;hp=6365e23db371892b4b14601606587bdefe534eb6;hpb=ab623c0e0b4815bd69a94887241a69aaa857ed26;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/live/live-utils.ts b/server/lib/live/live-utils.ts index 6365e23db..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' import { logger } from '@server/helpers/logger' import { MStreamingPlaylist, MVideo } from '@server/types/models' import { getLiveDirectory } from '../paths' +import { LiveSegmentShaStore } from './live-segment-sha-store' function buildConcatenatedName (segmentOrPlaylistPath: string) { const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/) @@ -10,25 +11,31 @@ function buildConcatenatedName (segmentOrPlaylistPath: string) { return 'concat-' + num[1] + '.ts' } -async function cleanupPermanentLive (video: MVideo, streamingPlaylist?: MStreamingPlaylist) { - const hlsDirectory = getLiveDirectory(video) - - await cleanupTMPLiveFiles(hlsDirectory) +async function cleanupPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { + await cleanupTMPLiveFiles(video) - if (streamingPlaylist) await streamingPlaylist.destroy() + await streamingPlaylist.destroy() } -async function cleanupNormalLive (video: MVideo, streamingPlaylist?: MStreamingPlaylist) { +async function cleanupUnsavedNormalLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { const hlsDirectory = getLiveDirectory(video) await remove(hlsDirectory) - if (streamingPlaylist) await streamingPlaylist.destroy() + await streamingPlaylist.destroy() + + LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid) } -async function cleanupTMPLiveFiles (hlsDirectory: string) { +async function cleanupTMPLiveFiles (video: MVideo) { + const hlsDirectory = getLiveDirectory(video) + + LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid) + if (!await pathExists(hlsDirectory)) return + logger.info('Cleanup TMP live files of %s.', hlsDirectory) + const files = await readdir(hlsDirectory) for (const filename of files) { @@ -49,7 +56,7 @@ async function cleanupTMPLiveFiles (hlsDirectory: string) { export { cleanupPermanentLive, - cleanupNormalLive, + cleanupUnsavedNormalLive, cleanupTMPLiveFiles, buildConcatenatedName }