import { expect } from 'chai'
import { pathExists, readdir } from 'fs-extra'
import { join } from 'path'
+import { sha1 } from '@shared/extra-utils'
import { LiveVideo, VideoStreamingPlaylistType } from '@shared/models'
import { ObjectStorageCommand, PeerTubeServer } from '@shared/server-commands'
import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist } from './streaming-playlists'
-async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, savedResolutions: number[] = []) {
+async function checkLiveCleanup (options: {
+ server: PeerTubeServer
+ videoUUID: string
+ permanent: boolean
+ savedResolutions?: number[]
+}) {
+ const { server, videoUUID, permanent, savedResolutions = [] } = options
+
const basePath = server.servers.buildDirectory('streaming-playlists')
const hlsPath = join(basePath, 'hls', videoUUID)
+ if (permanent) {
+ if (!await pathExists(hlsPath)) return
+
+ const files = await readdir(hlsPath)
+ expect(files).to.have.lengthOf(0)
+ return
+ }
+
if (savedResolutions.length === 0) {
return checkUnsavedLiveCleanup(server, videoUUID, hlsPath)
}
liveVideoId: string
resolutions: number[]
transcoded: boolean
+
objectStorage: boolean
+ objectStorageBaseUrl?: string
}) {
- const { originServer, servers, liveVideoId, resolutions, transcoded, objectStorage } = options
+ const {
+ originServer,
+ servers,
+ liveVideoId,
+ resolutions,
+ transcoded,
+ objectStorage,
+ objectStorageBaseUrl = ObjectStorageCommand.getMockPlaylistBaseUrl()
+ } = options
for (const server of servers) {
const { data } = await server.videos.list()
})
if (objectStorage) {
- expect(hlsPlaylist.playlistUrl).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl())
+ expect(hlsPlaylist.playlistUrl).to.contain(objectStorageBaseUrl)
}
for (let i = 0; i < resolutions.length; i++) {
videoUUID: video.uuid,
playlistNumber: i,
segment: segmentNum,
- objectStorage
+ objectStorage,
+ objectStorageBaseUrl
})
const baseUrl = objectStorage
- ? ObjectStorageCommand.getMockPlaylistBaseUrl() + 'hls'
+ ? join(objectStorageBaseUrl, 'hls')
: originServer.url + '/static/streaming-playlists/hls'
if (objectStorage) {
- expect(hlsPlaylist.segmentsSha256Url).to.contain(ObjectStorageCommand.getMockPlaylistBaseUrl())
+ expect(hlsPlaylist.segmentsSha256Url).to.contain(objectStorageBaseUrl)
}
const subPlaylist = await originServer.streamingPlaylists.get({
segmentName,
hlsPlaylist
})
+
+ if (originServer.internalServerNumber === server.internalServerNumber) {
+ const infohash = sha1(`${2 + hlsPlaylist.playlistUrl}+V${i}`)
+ const dbInfohashes = await originServer.sql.getPlaylistInfohash(hlsPlaylist.id)
+
+ expect(dbInfohashes).to.include(infohash)
+ }
}
}
}