2021-12-17 05:58:15 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import { expect } from 'chai'
|
|
|
|
import { pathExists, readdir } from 'fs-extra'
|
|
|
|
import { join } from 'path'
|
2022-05-25 08:54:16 -04:00
|
|
|
import { LiveVideo } from '@shared/models'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { PeerTubeServer } from '@shared/server-commands'
|
|
|
|
|
2022-04-21 03:06:52 -04:00
|
|
|
async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) {
|
2022-05-25 08:54:16 -04:00
|
|
|
let live: LiveVideo
|
|
|
|
|
|
|
|
try {
|
|
|
|
live = await server.live.get({ videoId: videoUUID })
|
|
|
|
} catch {}
|
|
|
|
|
2021-12-17 05:58:15 -05:00
|
|
|
const basePath = server.servers.buildDirectory('streaming-playlists')
|
|
|
|
const hlsPath = join(basePath, 'hls', videoUUID)
|
|
|
|
|
2022-04-21 03:06:52 -04:00
|
|
|
if (savedResolutions.length === 0) {
|
2022-05-25 08:54:16 -04:00
|
|
|
|
|
|
|
if (live?.permanentLive) {
|
|
|
|
expect(await pathExists(hlsPath)).to.be.true
|
|
|
|
|
|
|
|
const hlsFiles = await readdir(hlsPath)
|
|
|
|
expect(hlsFiles).to.have.lengthOf(1) // Only replays directory
|
|
|
|
|
|
|
|
const replayDir = join(hlsPath, 'replay')
|
|
|
|
expect(await pathExists(replayDir)).to.be.true
|
|
|
|
|
|
|
|
const replayFiles = await readdir(join(hlsPath, 'replay'))
|
|
|
|
expect(replayFiles).to.have.lengthOf(0)
|
|
|
|
} else {
|
|
|
|
expect(await pathExists(hlsPath)).to.be.false
|
|
|
|
}
|
2021-12-17 05:58:15 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const files = await readdir(hlsPath)
|
|
|
|
|
|
|
|
// fragmented file and playlist per resolution + master playlist + segments sha256 json file
|
2022-04-21 03:06:52 -04:00
|
|
|
expect(files).to.have.lengthOf(savedResolutions.length * 2 + 2)
|
2021-12-17 05:58:15 -05:00
|
|
|
|
2022-04-21 03:06:52 -04:00
|
|
|
for (const resolution of savedResolutions) {
|
2021-12-17 05:58:15 -05:00
|
|
|
const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`))
|
|
|
|
expect(fragmentedFile).to.exist
|
|
|
|
|
|
|
|
const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`))
|
|
|
|
expect(playlistFile).to.exist
|
|
|
|
}
|
|
|
|
|
|
|
|
const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8'))
|
|
|
|
expect(masterPlaylistFile).to.exist
|
|
|
|
|
|
|
|
const shaFile = files.find(f => f.endsWith('-segments-sha256.json'))
|
|
|
|
expect(shaFile).to.exist
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2022-04-21 03:06:52 -04:00
|
|
|
checkLiveCleanup
|
2021-12-17 05:58:15 -05:00
|
|
|
}
|