2021-11-17 16:04:53 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import { expect } from 'chai'
|
2022-07-29 14:50:41 +02:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2021-12-17 11:58:15 +01:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createMultipleServers,
|
|
|
|
doubleFollow,
|
2022-07-29 14:50:41 +02:00
|
|
|
makeRawRequest,
|
2021-12-17 11:58:15 +01:00
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/server-commands'
|
2021-11-17 16:04:53 +01:00
|
|
|
|
|
|
|
describe('Test videos files', function () {
|
|
|
|
let servers: PeerTubeServer[]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(150_000)
|
|
|
|
|
|
|
|
servers = await createMultipleServers(2)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
|
|
|
await servers[0].config.enableTranscoding(true, true)
|
2022-07-29 14:50:41 +02:00
|
|
|
})
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
describe('When deleting all files', function () {
|
|
|
|
let validId1: string
|
|
|
|
let validId2: string
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
before(async function () {
|
2022-09-28 08:24:18 +02:00
|
|
|
this.timeout(360_000)
|
2022-08-01 16:05:41 +02:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
{
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
|
|
|
|
validId1 = uuid
|
|
|
|
}
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
{
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'video 2' })
|
|
|
|
validId2 = uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should delete webtorrent files', async function () {
|
|
|
|
this.timeout(30_000)
|
|
|
|
|
|
|
|
await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId1 })
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const video = await server.videos.get({ id: validId1 })
|
|
|
|
|
|
|
|
expect(video.files).to.have.lengthOf(0)
|
|
|
|
expect(video.streamingPlaylists).to.have.lengthOf(1)
|
|
|
|
}
|
|
|
|
})
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
it('Should delete HLS files', async function () {
|
|
|
|
this.timeout(30_000)
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
await servers[0].videos.removeHLSPlaylist({ videoId: validId2 })
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
await waitJobs(servers)
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
for (const server of servers) {
|
|
|
|
const video = await server.videos.get({ id: validId2 })
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
expect(video.files).to.have.length.above(0)
|
|
|
|
expect(video.streamingPlaylists).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
})
|
2021-11-17 16:04:53 +01:00
|
|
|
})
|
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
describe('When deleting a specific file', function () {
|
|
|
|
let webtorrentId: string
|
|
|
|
let hlsId: string
|
|
|
|
|
|
|
|
before(async function () {
|
2022-08-01 16:05:41 +02:00
|
|
|
this.timeout(120_000)
|
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
{
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'webtorrent' })
|
|
|
|
webtorrentId = uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'hls' })
|
|
|
|
hlsId = uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Shoulde delete a webtorrent file', async function () {
|
2022-08-01 16:05:41 +02:00
|
|
|
this.timeout(30_000)
|
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
const video = await servers[0].videos.get({ id: webtorrentId })
|
|
|
|
const files = video.files
|
|
|
|
|
|
|
|
await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentId, fileId: files[0].id })
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const video = await server.videos.get({ id: webtorrentId })
|
|
|
|
|
|
|
|
expect(video.files).to.have.lengthOf(files.length - 1)
|
|
|
|
expect(video.files.find(f => f.id === files[0].id)).to.not.exist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should delete all webtorrent files', async function () {
|
2022-08-01 16:05:41 +02:00
|
|
|
this.timeout(30_000)
|
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
const video = await servers[0].videos.get({ id: webtorrentId })
|
|
|
|
const files = video.files
|
|
|
|
|
|
|
|
for (const file of files) {
|
|
|
|
await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentId, fileId: file.id })
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const video = await server.videos.get({ id: webtorrentId })
|
|
|
|
|
|
|
|
expect(video.files).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should delete a hls file', async function () {
|
2022-08-01 16:05:41 +02:00
|
|
|
this.timeout(30_000)
|
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
const video = await servers[0].videos.get({ id: hlsId })
|
|
|
|
const files = video.streamingPlaylists[0].files
|
|
|
|
const toDelete = files[0]
|
|
|
|
|
|
|
|
await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: toDelete.id })
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const video = await server.videos.get({ id: hlsId })
|
|
|
|
|
|
|
|
expect(video.streamingPlaylists[0].files).to.have.lengthOf(files.length - 1)
|
|
|
|
expect(video.streamingPlaylists[0].files.find(f => f.id === toDelete.id)).to.not.exist
|
|
|
|
|
2022-10-12 16:09:02 +02:00
|
|
|
const { text } = await makeRawRequest({ url: video.streamingPlaylists[0].playlistUrl, expectedStatus: HttpStatusCode.OK_200 })
|
2022-07-29 14:50:41 +02:00
|
|
|
|
|
|
|
expect(text.includes(`-${toDelete.resolution.id}.m3u8`)).to.be.false
|
|
|
|
expect(text.includes(`-${video.streamingPlaylists[0].files[0].resolution.id}.m3u8`)).to.be.true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should delete all hls files', async function () {
|
2022-08-01 16:05:41 +02:00
|
|
|
this.timeout(30_000)
|
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
const video = await servers[0].videos.get({ id: hlsId })
|
|
|
|
const files = video.streamingPlaylists[0].files
|
|
|
|
|
|
|
|
for (const file of files) {
|
|
|
|
await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: file.id })
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const video = await server.videos.get({ id: hlsId })
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
expect(video.streamingPlaylists).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
})
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
it('Should not delete last file of a video', async function () {
|
2022-08-01 16:05:41 +02:00
|
|
|
this.timeout(60_000)
|
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
const webtorrentOnly = await servers[0].videos.get({ id: hlsId })
|
|
|
|
const hlsOnly = await servers[0].videos.get({ id: webtorrentId })
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentOnly.id, fileId: webtorrentOnly.files[i].id })
|
|
|
|
await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[i].id })
|
|
|
|
}
|
2021-11-17 16:04:53 +01:00
|
|
|
|
2022-07-29 14:50:41 +02:00
|
|
|
const expectedStatus = HttpStatusCode.BAD_REQUEST_400
|
|
|
|
await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentOnly.id, fileId: webtorrentOnly.files[4].id, expectedStatus })
|
|
|
|
await servers[0].videos.removeHLSFile({ videoId: hlsOnly.id, fileId: hlsOnly.streamingPlaylists[0].files[4].id, expectedStatus })
|
|
|
|
})
|
2021-11-17 16:04:53 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|