1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { pathExists, readdir } from 'fs-extra'
5 import { join } from 'path'
6 import { LiveVideo } from '@shared/models'
7 import { PeerTubeServer } from '@shared/server-commands'
9 async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) {
13 live = await server.live.get({ videoId: videoUUID })
16 const basePath = server.servers.buildDirectory('streaming-playlists')
17 const hlsPath = join(basePath, 'hls', videoUUID)
19 if (savedResolutions.length === 0) {
21 if (live?.permanentLive) {
22 expect(await pathExists(hlsPath)).to.be.true
24 const hlsFiles = await readdir(hlsPath)
25 expect(hlsFiles).to.have.lengthOf(1) // Only replays directory
27 const replayDir = join(hlsPath, 'replay')
28 expect(await pathExists(replayDir)).to.be.true
30 const replayFiles = await readdir(join(hlsPath, 'replay'))
31 expect(replayFiles).to.have.lengthOf(0)
33 expect(await pathExists(hlsPath)).to.be.false
39 const files = await readdir(hlsPath)
41 // fragmented file and playlist per resolution + master playlist + segments sha256 json file
42 expect(files).to.have.lengthOf(savedResolutions.length * 2 + 2)
44 for (const resolution of savedResolutions) {
45 const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`))
46 expect(fragmentedFile).to.exist
48 const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`))
49 expect(playlistFile).to.exist
52 const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8'))
53 expect(masterPlaylistFile).to.exist
55 const shaFile = files.find(f => f.endsWith('-segments-sha256.json'))
56 expect(shaFile).to.exist