aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/video-live-ending.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts
new file mode 100644
index 000000000..1a58a9f7e
--- /dev/null
+++ b/server/lib/job-queue/handlers/video-live-ending.ts
@@ -0,0 +1,47 @@
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}