From 1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Jul 2022 14:50:41 +0200 Subject: Add ability to delete a specific video file --- server/tests/api/check-params/video-files.ts | 80 +++++++--- server/tests/api/transcoding/create-transcoding.ts | 4 +- server/tests/api/videos/video-files.ts | 172 +++++++++++++++++---- 3 files changed, 204 insertions(+), 52 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/video-files.ts b/server/tests/api/check-params/video-files.ts index 8c0795092..c698bea82 100644 --- a/server/tests/api/check-params/video-files.ts +++ b/server/tests/api/check-params/video-files.ts @@ -24,6 +24,12 @@ describe('Test videos files', function () { let validId1: string let validId2: string + let hlsFileId: number + let webtorrentFileId: number + + let remoteHLSFileId: number + let remoteWebtorrentFileId: number + // --------------------------------------------------------------- before(async function () { @@ -39,7 +45,12 @@ describe('Test videos files', function () { { const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' }) - remoteId = uuid + await waitJobs(servers) + + const video = await servers[1].videos.get({ id: uuid }) + remoteId = video.uuid + remoteHLSFileId = video.streamingPlaylists[0].files[0].id + remoteWebtorrentFileId = video.files[0].id } { @@ -47,7 +58,12 @@ describe('Test videos files', function () { { const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' }) - validId1 = uuid + await waitJobs(servers) + + const video = await servers[0].videos.get({ id: uuid }) + validId1 = video.uuid + hlsFileId = video.streamingPlaylists[0].files[0].id + webtorrentFileId = video.files[0].id } { @@ -76,43 +92,67 @@ describe('Test videos files', function () { }) it('Should not delete files of a unknown video', async function () { - await servers[0].videos.removeHLSFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await servers[0].videos.removeWebTorrentFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + const expectedStatus = HttpStatusCode.NOT_FOUND_404 + + await servers[0].videos.removeHLSPlaylist({ videoId: 404, expectedStatus }) + await servers[0].videos.removeAllWebTorrentFiles({ videoId: 404, expectedStatus }) + + await servers[0].videos.removeHLSFile({ videoId: 404, fileId: hlsFileId, expectedStatus }) + await servers[0].videos.removeWebTorrentFile({ videoId: 404, fileId: webtorrentFileId, expectedStatus }) + }) + + it('Should not delete unknown files', async function () { + const expectedStatus = HttpStatusCode.NOT_FOUND_404 + + await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: webtorrentFileId, expectedStatus }) + await servers[0].videos.removeWebTorrentFile({ videoId: validId1, fileId: hlsFileId, expectedStatus }) }) it('Should not delete files of a remote video', async function () { - await servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const expectedStatus = HttpStatusCode.BAD_REQUEST_400 + + await servers[0].videos.removeHLSPlaylist({ videoId: remoteId, expectedStatus }) + await servers[0].videos.removeAllWebTorrentFiles({ videoId: remoteId, expectedStatus }) + + await servers[0].videos.removeHLSFile({ videoId: remoteId, fileId: remoteHLSFileId, expectedStatus }) + await servers[0].videos.removeWebTorrentFile({ videoId: remoteId, fileId: remoteWebtorrentFileId, expectedStatus }) }) it('Should not delete files by a non admin user', async function () { const expectedStatus = HttpStatusCode.FORBIDDEN_403 - await servers[0].videos.removeHLSFiles({ videoId: validId1, token: userToken, expectedStatus }) - await servers[0].videos.removeHLSFiles({ videoId: validId1, token: moderatorToken, expectedStatus }) + await servers[0].videos.removeHLSPlaylist({ videoId: validId1, token: userToken, expectedStatus }) + await servers[0].videos.removeHLSPlaylist({ videoId: validId1, token: moderatorToken, expectedStatus }) + + await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId1, token: userToken, expectedStatus }) + await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId1, token: moderatorToken, expectedStatus }) - await servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: userToken, expectedStatus }) - await servers[0].videos.removeWebTorrentFiles({ videoId: validId1, token: moderatorToken, expectedStatus }) + await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId, token: userToken, expectedStatus }) + await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId, token: moderatorToken, expectedStatus }) + + await servers[0].videos.removeWebTorrentFile({ videoId: validId1, fileId: webtorrentFileId, token: userToken, expectedStatus }) + await servers[0].videos.removeWebTorrentFile({ videoId: validId1, fileId: webtorrentFileId, token: moderatorToken, expectedStatus }) }) it('Should not delete files if the files are not available', async function () { - await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - }) + await servers[0].videos.removeHLSPlaylist({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[0].videos.removeAllWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - it('Should not delete files if no both versions are available', async function () { - await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[0].videos.removeHLSFile({ videoId: hlsId, fileId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videos.removeWebTorrentFile({ videoId: webtorrentId, fileId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should not delete files if no both versions are available', async function () { - await servers[0].videos.removeHLSFiles({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await servers[0].videos.removeWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[0].videos.removeHLSPlaylist({ videoId: hlsId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[0].videos.removeAllWebTorrentFiles({ videoId: webtorrentId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should delete files if both versions are available', async function () { - await servers[0].videos.removeHLSFiles({ videoId: validId1 }) - await servers[0].videos.removeWebTorrentFiles({ videoId: validId2 }) + await servers[0].videos.removeHLSFile({ videoId: validId1, fileId: hlsFileId }) + await servers[0].videos.removeWebTorrentFile({ videoId: validId1, fileId: webtorrentFileId }) + + await servers[0].videos.removeHLSPlaylist({ videoId: validId1 }) + await servers[0].videos.removeAllWebTorrentFiles({ videoId: validId2 }) }) after(async function () { diff --git a/server/tests/api/transcoding/create-transcoding.ts b/server/tests/api/transcoding/create-transcoding.ts index e3867fdad..b59bef772 100644 --- a/server/tests/api/transcoding/create-transcoding.ts +++ b/server/tests/api/transcoding/create-transcoding.ts @@ -122,7 +122,7 @@ function runTests (objectStorage: boolean) { it('Should generate WebTorrent from HLS only video', async function () { this.timeout(60000) - await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID }) + await servers[0].videos.removeAllWebTorrentFiles({ videoId: videoUUID }) await waitJobs(servers) await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' }) @@ -142,7 +142,7 @@ function runTests (objectStorage: boolean) { it('Should only generate WebTorrent', async function () { this.timeout(60000) - await servers[0].videos.removeHLSFiles({ videoId: videoUUID }) + await servers[0].videos.removeHLSPlaylist({ videoId: videoUUID }) await waitJobs(servers) await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' }) diff --git a/server/tests/api/videos/video-files.ts b/server/tests/api/videos/video-files.ts index b0ef4a2e9..313f020e9 100644 --- a/server/tests/api/videos/video-files.ts +++ b/server/tests/api/videos/video-files.ts @@ -2,10 +2,12 @@ import 'mocha' import { expect } from 'chai' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createMultipleServers, doubleFollow, + makeRawRequest, PeerTubeServer, setAccessTokensToServers, waitJobs @@ -13,8 +15,6 @@ import { describe('Test videos files', function () { let servers: PeerTubeServer[] - let validId1: string - let validId2: string // --------------------------------------------------------------- @@ -27,48 +27,160 @@ describe('Test videos files', function () { await doubleFollow(servers[0], servers[1]) await servers[0].config.enableTranscoding(true, true) + }) - { - const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' }) - validId1 = uuid - } + describe('When deleting all files', function () { + let validId1: string + let validId2: string - { - const { uuid } = await servers[0].videos.quickUpload({ name: 'video 2' }) - validId2 = uuid - } + before(async function () { + { + const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' }) + validId1 = uuid + } - await waitJobs(servers) - }) + { + 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) + } + }) - it('Should delete webtorrent files', async function () { - this.timeout(30_000) + it('Should delete HLS files', async function () { + this.timeout(30_000) - await servers[0].videos.removeWebTorrentFiles({ videoId: validId1 }) + await servers[0].videos.removeHLSPlaylist({ videoId: validId2 }) - await waitJobs(servers) + await waitJobs(servers) - for (const server of servers) { - const video = await server.videos.get({ id: validId1 }) + for (const server of servers) { + const video = await server.videos.get({ id: validId2 }) - expect(video.files).to.have.lengthOf(0) - expect(video.streamingPlaylists).to.have.lengthOf(1) - } + expect(video.files).to.have.length.above(0) + expect(video.streamingPlaylists).to.have.lengthOf(0) + } + }) }) - it('Should delete HLS files', async function () { - this.timeout(30_000) + describe('When deleting a specific file', function () { + let webtorrentId: string + let hlsId: string + + before(async function () { + { + 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 () { + 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 () { + 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 () { + 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 + + const { text } = await makeRawRequest(video.streamingPlaylists[0].playlistUrl) + + 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 () { + 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 }) - await servers[0].videos.removeHLSFiles({ videoId: validId2 }) + expect(video.streamingPlaylists).to.have.lengthOf(0) + } + }) - await waitJobs(servers) + it('Should not delete last file of a video', async function () { + const webtorrentOnly = await servers[0].videos.get({ id: hlsId }) + const hlsOnly = await servers[0].videos.get({ id: webtorrentId }) - for (const server of servers) { - const video = await server.videos.get({ id: validId2 }) + 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 }) + } - expect(video.files).to.have.length.above(0) - expect(video.streamingPlaylists).to.have.lengthOf(0) - } + 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 }) + }) }) after(async function () { -- cgit v1.2.3