|
@@ -1,24 +1,26 @@
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
-import { expect } from 'chai'
|
|
|
import { getAllFiles } from '@peertube/peertube-core-utils'
|
|
|
-import { HttpStatusCode } from '@peertube/peertube-models'
|
|
|
-import { expectStartWith } from '@tests/shared/checks.js'
|
|
|
+import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
|
|
|
import { areMockObjectStorageTestsDisabled } from '@peertube/peertube-node-utils'
|
|
|
import {
|
|
|
+ ObjectStorageCommand,
|
|
|
+ PeerTubeServer,
|
|
|
cleanupTests,
|
|
|
createMultipleServers,
|
|
|
- doubleFollow,
|
|
|
- makeGetRequest,
|
|
|
+ doubleFollow, makeGetRequest,
|
|
|
makeRawRequest,
|
|
|
- ObjectStorageCommand,
|
|
|
- PeerTubeServer,
|
|
|
setAccessTokensToServers,
|
|
|
setDefaultAccountAvatar,
|
|
|
setDefaultVideoChannel,
|
|
|
waitJobs
|
|
|
} from '@peertube/peertube-server-commands'
|
|
|
+import { expectStartWith } from '@tests/shared/checks.js'
|
|
|
+import { checkDirectoryIsEmpty } from '@tests/shared/directories.js'
|
|
|
+import { FIXTURE_URLS } from '@tests/shared/tests.js'
|
|
|
+import { checkSourceFile } from '@tests/shared/videos.js'
|
|
|
+import { expect } from 'chai'
|
|
|
|
|
|
-describe('Test a video file replacement', function () {
|
|
|
+describe('Test video source management', function () {
|
|
|
let servers: PeerTubeServer[] = []
|
|
|
|
|
|
let replaceDate: Date
|
|
@@ -36,6 +38,7 @@ describe('Test a video file replacement', function () {
|
|
|
await setDefaultAccountAvatar(servers)
|
|
|
|
|
|
await servers[0].config.enableFileUpdate()
|
|
|
+ await servers[0].config.enableMinimumTranscoding()
|
|
|
|
|
|
userToken = await servers[0].users.generateUserAndToken('user1')
|
|
|
|
|
@@ -44,30 +47,95 @@ describe('Test a video file replacement', function () {
|
|
|
})
|
|
|
|
|
|
describe('Getting latest video source', () => {
|
|
|
- const fixture = 'video_short.webm'
|
|
|
+ const fixture1 = 'video_short.webm'
|
|
|
+ const fixture2 = 'video_short1.webm'
|
|
|
+
|
|
|
const uuids: string[] = []
|
|
|
|
|
|
- it('Should get the source filename with legacy upload', async function () {
|
|
|
+ it('Should get the source filename with legacy upload with disabled keep original file', async function () {
|
|
|
this.timeout(30000)
|
|
|
|
|
|
- const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video', fixture }, mode: 'legacy' })
|
|
|
+ const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video', fixture: fixture1 }, mode: 'legacy' })
|
|
|
uuids.push(uuid)
|
|
|
|
|
|
+ await waitJobs(servers)
|
|
|
+
|
|
|
const source = await servers[0].videos.getSource({ id: uuid })
|
|
|
- expect(source.filename).to.equal(fixture)
|
|
|
+ expect(source.filename).to.equal(fixture1)
|
|
|
+ expect(source.inputFilename).to.equal(fixture1)
|
|
|
+ expect(source.fileDownloadUrl).to.be.null
|
|
|
+
|
|
|
+ expect(source.createdAt).to.exist
|
|
|
+ expect(source.fps).to.equal(25)
|
|
|
+ expect(source.height).to.equal(720)
|
|
|
+ expect(source.width).to.equal(1280)
|
|
|
+ expect(source.resolution.id).to.equal(720)
|
|
|
+ expect(source.size).to.equal(218910)
|
|
|
+
|
|
|
+ expect(source.metadata?.format).to.exist
|
|
|
+ expect(source.metadata?.streams).to.be.an('array')
|
|
|
+
|
|
|
+ await checkDirectoryIsEmpty(servers[0], 'original-video-files')
|
|
|
})
|
|
|
|
|
|
- it('Should get the source filename with resumable upload', async function () {
|
|
|
+ it('Should get the source filename with resumable upload and enabled keep original file', async function () {
|
|
|
this.timeout(30000)
|
|
|
|
|
|
- const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video', fixture }, mode: 'resumable' })
|
|
|
+ await servers[0].config.keepSourceFile()
|
|
|
+
|
|
|
+ const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video', fixture: fixture2 }, mode: 'resumable' })
|
|
|
uuids.push(uuid)
|
|
|
|
|
|
+ await waitJobs(servers)
|
|
|
+
|
|
|
const source = await servers[0].videos.getSource({ id: uuid })
|
|
|
- expect(source.filename).to.equal(fixture)
|
|
|
+ expect(source.filename).to.equal(fixture2)
|
|
|
+ expect(source.inputFilename).to.equal(fixture2)
|
|
|
+ expect(source.fileDownloadUrl).to.exist
|
|
|
+
|
|
|
+ expect(source.createdAt).to.exist
|
|
|
+ expect(source.fps).to.equal(25)
|
|
|
+ expect(source.height).to.equal(720)
|
|
|
+ expect(source.width).to.equal(1280)
|
|
|
+ expect(source.resolution.id).to.equal(720)
|
|
|
+ expect(source.size).to.equal(572456)
|
|
|
+
|
|
|
+ expect(source.metadata?.format).to.exist
|
|
|
+ expect(source.metadata?.streams).to.be.an('array')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('Should have kept original video file', async function () {
|
|
|
+ await checkSourceFile({ server: servers[0], fsCount: 1, fixture: fixture2, uuid: uuids[uuids.length - 1] })
|
|
|
+ })
|
|
|
+
|
|
|
+ it('Should transcode a file but do not replace original file', async function () {
|
|
|
+ await servers[0].videos.runTranscoding({ transcodingType: 'web-video', videoId: uuids[0] })
|
|
|
+ await servers[0].videos.runTranscoding({ transcodingType: 'web-video', videoId: uuids[1] })
|
|
|
+
|
|
|
+ await checkSourceFile({ server: servers[0], fsCount: 1, fixture: fixture2, uuid: uuids[uuids.length - 1] })
|
|
|
+ })
|
|
|
+
|
|
|
+ it('Should also keep audio files', async function () {
|
|
|
+ const fixture = 'sample.ogg'
|
|
|
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'audio', fixture })
|
|
|
+ uuids.push(uuid)
|
|
|
+
|
|
|
+ await waitJobs(servers)
|
|
|
+ const source = await checkSourceFile({ server: servers[0], fsCount: 2, fixture, uuid })
|
|
|
+
|
|
|
+ expect(source.createdAt).to.exist
|
|
|
+ expect(source.fps).to.equal(0)
|
|
|
+ expect(source.height).to.equal(0)
|
|
|
+ expect(source.width).to.equal(0)
|
|
|
+ expect(source.resolution.id).to.equal(0)
|
|
|
+ expect(source.resolution.label).to.equal('Audio')
|
|
|
+ expect(source.size).to.equal(105243)
|
|
|
+
|
|
|
+ expect(source.metadata?.format).to.exist
|
|
|
+ expect(source.metadata?.streams).to.be.an('array')
|
|
|
})
|
|
|
|
|
|
- after(async function () {
|
|
|
+ it('Should delete all videos and do not have original files anymore', async function () {
|
|
|
this.timeout(60000)
|
|
|
|
|
|
for (const uuid of uuids) {
|
|
@@ -75,6 +143,23 @@ describe('Test a video file replacement', function () {
|
|
|
}
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
+
|
|
|
+ await checkDirectoryIsEmpty(servers[0], 'original-video-files')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('Should not have source on import', async function () {
|
|
|
+ const { video: { uuid } } = await servers[0].videoImports.importVideo({
|
|
|
+ attributes: {
|
|
|
+ channelId: servers[0].store.channel.id,
|
|
|
+ targetUrl: FIXTURE_URLS.goodVideo,
|
|
|
+ privacy: VideoPrivacy.PUBLIC
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ await waitJobs(servers)
|
|
|
+
|
|
|
+ await servers[0].videos.getSource({ id: uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
|
|
+ await checkDirectoryIsEmpty(servers[0], 'original-video-files')
|
|
|
})
|
|
|
})
|
|
|
|
|
@@ -110,18 +195,25 @@ describe('Test a video file replacement', function () {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+ it('Should not have kept original video file', async function () {
|
|
|
+ await checkDirectoryIsEmpty(servers[0], 'original-video-files')
|
|
|
+ })
|
|
|
+
|
|
|
it('Should replace a video file with transcoding enabled', async function () {
|
|
|
this.timeout(240000)
|
|
|
|
|
|
const previousPaths: string[] = []
|
|
|
|
|
|
- await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true })
|
|
|
+ await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true, keepOriginal: true })
|
|
|
|
|
|
- const { uuid: videoUUID } = await servers[0].videos.quickUpload({ name: 'fs with transcoding', fixture: 'video_short_720p.mp4' })
|
|
|
+ const uploadFixture = 'video_short_720p.mp4'
|
|
|
+ const { uuid: videoUUID } = await servers[0].videos.quickUpload({ name: 'fs with transcoding', fixture: uploadFixture })
|
|
|
uuid = videoUUID
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
+ await checkSourceFile({ server: servers[0], fsCount: 1, uuid, fixture: uploadFixture })
|
|
|
+
|
|
|
for (const server of servers) {
|
|
|
const video = await server.videos.get({ id: uuid })
|
|
|
expect(video.inputFileUpdatedAt).to.be.null
|
|
@@ -151,9 +243,23 @@ describe('Test a video file replacement', function () {
|
|
|
|
|
|
replaceDate = new Date()
|
|
|
|
|
|
- await servers[0].videos.replaceSourceFile({ videoId: uuid, fixture: 'video_short_360p.mp4' })
|
|
|
+ const replaceFixture = 'video_short_360p.mp4'
|
|
|
+ await servers[0].videos.replaceSourceFile({ videoId: uuid, fixture: replaceFixture })
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
+ const source = await checkSourceFile({ server: servers[0], fsCount: 1, uuid, fixture: replaceFixture })
|
|
|
+
|
|
|
+ expect(source.createdAt).to.exist
|
|
|
+ expect(source.fps).to.equal(25)
|
|
|
+ expect(source.height).to.equal(360)
|
|
|
+ expect(source.width).to.equal(640)
|
|
|
+ expect(source.resolution.id).to.equal(360)
|
|
|
+ expect(source.resolution.label).to.equal('360p')
|
|
|
+ expect(source.size).to.equal(30620)
|
|
|
+
|
|
|
+ expect(source.metadata?.format).to.exist
|
|
|
+ expect(source.metadata?.streams).to.be.an('array')
|
|
|
+
|
|
|
for (const server of servers) {
|
|
|
const video = await server.videos.get({ id: uuid })
|
|
|
|
|
@@ -189,35 +295,36 @@ describe('Test a video file replacement', function () {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- await servers[0].config.enableMinimumTranscoding()
|
|
|
+ await servers[0].config.enableMinimumTranscoding({ keepOriginal: true })
|
|
|
})
|
|
|
|
|
|
it('Should have cleaned up old files', async function () {
|
|
|
{
|
|
|
const count = await servers[0].servers.countFiles('storyboards')
|
|
|
- expect(count).to.equal(2)
|
|
|
+ expect(count).to.equal(3)
|
|
|
}
|
|
|
|
|
|
{
|
|
|
const count = await servers[0].servers.countFiles('web-videos')
|
|
|
- expect(count).to.equal(5 + 1) // +1 for private directory
|
|
|
+ expect(count).to.equal(6 + 1) // +1 for private directory
|
|
|
}
|
|
|
|
|
|
{
|
|
|
const count = await servers[0].servers.countFiles('streaming-playlists/hls')
|
|
|
- expect(count).to.equal(1 + 1) // +1 for private directory
|
|
|
+ expect(count).to.equal(2 + 1) // +1 for private directory
|
|
|
}
|
|
|
|
|
|
{
|
|
|
const count = await servers[0].servers.countFiles('torrents')
|
|
|
- expect(count).to.equal(9)
|
|
|
+ expect(count).to.equal(11)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- it('Should have the correct source input', async function () {
|
|
|
+ it('Should have the correct source input filename', async function () {
|
|
|
const source = await servers[0].videos.getSource({ id: uuid })
|
|
|
|
|
|
expect(source.filename).to.equal('video_short_360p.mp4')
|
|
|
+ expect(source.inputFilename).to.equal('video_short_360p.mp4')
|
|
|
expect(new Date(source.createdAt)).to.be.above(replaceDate)
|
|
|
})
|
|
|
|
|
@@ -367,6 +474,9 @@ describe('Test a video file replacement', function () {
|
|
|
expect(files[0].resolution.id).to.equal(360)
|
|
|
expectStartWith(files[0].fileUrl, objectStorage.getMockWebVideosBaseUrl())
|
|
|
}
|
|
|
+
|
|
|
+ const source = await servers[0].videos.getSource({ id: uuid })
|
|
|
+ expect(source.fileDownloadUrl).to.not.exist
|
|
|
})
|
|
|
|
|
|
it('Should replace a video file with transcoding enabled', async function () {
|
|
@@ -374,16 +484,25 @@ describe('Test a video file replacement', function () {
|
|
|
|
|
|
const previousPaths: string[] = []
|
|
|
|
|
|
- await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true })
|
|
|
+ await servers[0].config.enableTranscoding({ hls: true, webVideo: true, with0p: true, keepOriginal: true })
|
|
|
|
|
|
+ const fixture1 = 'video_short_360p.mp4'
|
|
|
const { uuid: videoUUID } = await servers[0].videos.quickUpload({
|
|
|
name: 'object storage with transcoding',
|
|
|
- fixture: 'video_short_360p.mp4'
|
|
|
+ fixture: fixture1
|
|
|
})
|
|
|
uuid = videoUUID
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
+ await checkSourceFile({
|
|
|
+ server: servers[0],
|
|
|
+ fixture: fixture1,
|
|
|
+ fsCount: 0,
|
|
|
+ uuid,
|
|
|
+ objectStorageBaseUrl: objectStorage?.getMockOriginalFileBaseUrl()
|
|
|
+ })
|
|
|
+
|
|
|
for (const server of servers) {
|
|
|
const video = await server.videos.get({ id: uuid })
|
|
|
|
|
@@ -403,9 +522,18 @@ describe('Test a video file replacement', function () {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- await servers[0].videos.replaceSourceFile({ videoId: uuid, fixture: 'video_short_240p.mp4' })
|
|
|
+ const fixture2 = 'video_short_240p.mp4'
|
|
|
+ await servers[0].videos.replaceSourceFile({ videoId: uuid, fixture: fixture2 })
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
+ await checkSourceFile({
|
|
|
+ server: servers[0],
|
|
|
+ fixture: fixture2,
|
|
|
+ fsCount: 0,
|
|
|
+ uuid,
|
|
|
+ objectStorageBaseUrl: objectStorage?.getMockOriginalFileBaseUrl()
|
|
|
+ })
|
|
|
+
|
|
|
for (const server of servers) {
|
|
|
const video = await server.videos.get({ id: uuid })
|
|
|
|