PeerTube/server/tests/cli/regenerate-thumbnails.ts

121 lines
3.8 KiB
TypeScript
Raw Normal View History

2021-03-12 10:04:49 -06:00
import 'mocha'
import { expect } from 'chai'
import { writeFile } from 'fs-extra'
import { basename, join } from 'path'
import { Video, VideoDetails } from '@shared/models'
2021-03-12 10:04:49 -06:00
import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
makeRawRequest,
ServerInfo,
setAccessTokensToServers,
uploadVideoAndGetId,
waitJobs
} from '../../../shared/extra-utils'
import { HttpStatusCode } from '@shared/core-utils'
async function testThumbnail (server: ServerInfo, videoId: number | string) {
const res = await getVideo(server.url, videoId)
const video: VideoDetails = res.body
const res1 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
expect(res1.body).to.not.have.lengthOf(0)
const res2 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
expect(res2.body).to.not.have.lengthOf(0)
}
2021-03-12 10:04:49 -06:00
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))
2021-07-13 02:43:59 -05:00
thumbnail1Path = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(video1.thumbnailPath))
2021-03-12 10:04:49 -06:00
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))
2021-07-13 02:43:59 -05:00
thumbnailRemotePath = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath))
2021-03-12 10:04:49 -06:00
}
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)
}
})
2021-04-08 03:08:11 -05:00
it('Should regenerate local thumbnails from the CLI', async function () {
2021-03-12 10:04:49 -06:00
this.timeout(15000)
2021-07-05 09:37:50 -05:00
await servers[0].cliCommand.execWithEnv(`npm run regenerate-thumbnails`)
2021-03-12 10:04:49 -06:00
})
it('Should have generated new thumbnail files', async function () {
await testThumbnail(servers[0], video1.uuid)
await testThumbnail(servers[0], video2.uuid)
2021-03-12 10:04:49 -06:00
const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200)
expect(res.body).to.have.lengthOf(0)
})
it('Should have deleted old thumbnail files', async function () {
{
await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.NOT_FOUND_404)
2021-03-12 10:04:49 -06:00
}
{
await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.NOT_FOUND_404)
2021-03-12 10:04:49 -06:00
}
{
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)
})
})