]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/video-live-ending.ts
Save
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-live-ending.ts
CommitLineData
a5cf76af
C
1import * as Bull from 'bull'
2import { readdir, remove } from 'fs-extra'
3import { join } from 'path'
4import { getHLSDirectory } from '@server/lib/video-paths'
5import { VideoModel } from '@server/models/video/video'
6import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
7import { VideoLiveEndingPayload } from '@shared/models'
8import { logger } from '../../../helpers/logger'
9
10async function processVideoLiveEnding (job: Bull.Job) {
11 const payload = job.data as VideoLiveEndingPayload
12
13 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId)
14 if (!video) {
15 logger.warn('Video live %d does not exist anymore. Cannot cleanup.', payload.videoId)
16 return
17 }
18
19 const streamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id)
20 const hlsDirectory = getHLSDirectory(video, false)
21
22 const files = await readdir(hlsDirectory)
23
24 for (const filename of files) {
25 if (
26 filename.endsWith('.ts') ||
27 filename.endsWith('.m3u8') ||
28 filename.endsWith('.mpd') ||
29 filename.endsWith('.m4s') ||
30 filename.endsWith('.tmp')
31 ) {
32 const p = join(hlsDirectory, filename)
33
34 remove(p)
35 .catch(err => logger.error('Cannot remove %s.', p, { err }))
36 }
37 }
38
39 streamingPlaylist.destroy()
40 .catch(err => logger.error('Cannot remove live streaming playlist.', { err }))
41}
42
43// ---------------------------------------------------------------------------
44
45export {
46 processVideoLiveEnding
47}