]>
Commit | Line | Data |
---|---|---|
c55e3d72 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { pathExists, readdir } from 'fs-extra' | |
5 | import { join } from 'path' | |
5333788c | 6 | import { LiveVideo } from '@shared/models' |
c55e3d72 C |
7 | import { PeerTubeServer } from '@shared/server-commands' |
8 | ||
4ec52d04 | 9 | async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) { |
5333788c C |
10 | let live: LiveVideo |
11 | ||
12 | try { | |
13 | live = await server.live.get({ videoId: videoUUID }) | |
14 | } catch {} | |
15 | ||
c55e3d72 C |
16 | const basePath = server.servers.buildDirectory('streaming-playlists') |
17 | const hlsPath = join(basePath, 'hls', videoUUID) | |
18 | ||
4ec52d04 | 19 | if (savedResolutions.length === 0) { |
5333788c C |
20 | |
21 | if (live?.permanentLive) { | |
22 | expect(await pathExists(hlsPath)).to.be.true | |
23 | ||
24 | const hlsFiles = await readdir(hlsPath) | |
25 | expect(hlsFiles).to.have.lengthOf(1) // Only replays directory | |
26 | ||
27 | const replayDir = join(hlsPath, 'replay') | |
28 | expect(await pathExists(replayDir)).to.be.true | |
29 | ||
30 | const replayFiles = await readdir(join(hlsPath, 'replay')) | |
31 | expect(replayFiles).to.have.lengthOf(0) | |
32 | } else { | |
33 | expect(await pathExists(hlsPath)).to.be.false | |
34 | } | |
c55e3d72 C |
35 | |
36 | return | |
37 | } | |
38 | ||
39 | const files = await readdir(hlsPath) | |
40 | ||
41 | // fragmented file and playlist per resolution + master playlist + segments sha256 json file | |
4ec52d04 | 42 | expect(files).to.have.lengthOf(savedResolutions.length * 2 + 2) |
c55e3d72 | 43 | |
4ec52d04 | 44 | for (const resolution of savedResolutions) { |
c55e3d72 C |
45 | const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`)) |
46 | expect(fragmentedFile).to.exist | |
47 | ||
48 | const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`)) | |
49 | expect(playlistFile).to.exist | |
50 | } | |
51 | ||
52 | const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8')) | |
53 | expect(masterPlaylistFile).to.exist | |
54 | ||
55 | const shaFile = files.find(f => f.endsWith('-segments-sha256.json')) | |
56 | expect(shaFile).to.exist | |
57 | } | |
58 | ||
59 | export { | |
4ec52d04 | 60 | checkLiveCleanup |
c55e3d72 | 61 | } |