mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add regenrate thumbnails scripts
This commit is contained in:
110
server/tests/cli/regenerate-thumbnails.ts
Normal file
110
server/tests/cli/regenerate-thumbnails.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import 'mocha'
|
||||
import { expect } from 'chai'
|
||||
import { writeFile } from 'fs-extra'
|
||||
import { basename, join } from 'path'
|
||||
import { Video } from '@shared/models'
|
||||
import {
|
||||
buildServerDirectory,
|
||||
cleanupTests,
|
||||
doubleFollow,
|
||||
execCLI,
|
||||
flushAndRunMultipleServers,
|
||||
getEnvCli,
|
||||
getVideo,
|
||||
makeRawRequest,
|
||||
ServerInfo,
|
||||
setAccessTokensToServers,
|
||||
uploadVideoAndGetId,
|
||||
waitJobs
|
||||
} from '../../../shared/extra-utils'
|
||||
import { HttpStatusCode } from '@shared/core-utils'
|
||||
|
||||
describe('Test regenerate thumbnails script', function () {
|
||||
let servers: ServerInfo[]
|
||||
|
||||
let video1: Video
|
||||
let video2: Video
|
||||
let remoteVideo: Video
|
||||
|
||||
let thumbnail1Path: string
|
||||
let thumbnailRemotePath: string
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
servers = await flushAndRunMultipleServers(2)
|
||||
await setAccessTokensToServers(servers)
|
||||
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
|
||||
{
|
||||
const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid
|
||||
video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body))
|
||||
|
||||
thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath))
|
||||
|
||||
const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid
|
||||
video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body))
|
||||
}
|
||||
|
||||
{
|
||||
const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid
|
||||
await waitJobs(servers)
|
||||
|
||||
remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body))
|
||||
|
||||
thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath))
|
||||
}
|
||||
|
||||
await writeFile(thumbnail1Path, '')
|
||||
await writeFile(thumbnailRemotePath, '')
|
||||
})
|
||||
|
||||
it('Should have empty thumbnails', async function () {
|
||||
{
|
||||
const res = await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.OK_200)
|
||||
expect(res.body).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
const res = await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.OK_200)
|
||||
expect(res.body).to.not.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200)
|
||||
expect(res.body).to.have.lengthOf(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should regenerate thumbnails from the CLI', async function () {
|
||||
this.timeout(15000)
|
||||
|
||||
const env = getEnvCli(servers[0])
|
||||
await execCLI(`${env} npm run regenerate-thumbnails`)
|
||||
})
|
||||
|
||||
it('Should have regenerated thumbbnails', async function () {
|
||||
{
|
||||
const res1 = await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.OK_200)
|
||||
expect(res1.body).to.not.have.lengthOf(0)
|
||||
|
||||
const res2 = await makeRawRequest(join(servers[0].url, video1.previewPath), HttpStatusCode.OK_200)
|
||||
expect(res2.body).to.not.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
const res = await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.OK_200)
|
||||
expect(res.body).to.not.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200)
|
||||
expect(res.body).to.have.lengthOf(0)
|
||||
}
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user