diff options
author | Chocobozzz <me@florianbigard.com> | 2020-09-25 10:04:21 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | a5cf76afa378aae81af2a9b0ce548e5d2582f832 (patch) | |
tree | 58da320232bee7c9656774c5d6811e82bbf6c696 /server/lib/job-queue/handlers/video-live-ending.ts | |
parent | de6310b2fcbb8a6b79c546b23dfa1920724faaa7 (diff) | |
download | PeerTube-a5cf76afa378aae81af2a9b0ce548e5d2582f832.tar.gz PeerTube-a5cf76afa378aae81af2a9b0ce548e5d2582f832.tar.zst PeerTube-a5cf76afa378aae81af2a9b0ce548e5d2582f832.zip |
Add watch messages if live has not started
Diffstat (limited to 'server/lib/job-queue/handlers/video-live-ending.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-live-ending.ts | 47 |
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 @@ | |||
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 | } | ||