]>
Commit | Line | Data |
---|---|---|
a5cf76af C |
1 | import * as Bull from 'bull' |
2 | import { readdir, remove } from 'fs-extra' | |
3 | import { join } from 'path' | |
4 | import { getHLSDirectory } from '@server/lib/video-paths' | |
5 | import { VideoModel } from '@server/models/video/video' | |
6 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' | |
7 | import { VideoLiveEndingPayload } from '@shared/models' | |
8 | import { logger } from '../../../helpers/logger' | |
9 | ||
10 | async 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 | ||
45 | export { | |
46 | processVideoLiveEnding | |
47 | } |