]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/regenerate-thumbnails.ts
Support short uuid for GET video/playlist
[github/Chocobozzz/PeerTube.git] / server / tests / cli / regenerate-thumbnails.ts
CommitLineData
c2bd7a6f
C
1import 'mocha'
2import { expect } from 'chai'
3import { writeFile } from 'fs-extra'
4import { basename, join } from 'path'
a0eeb45f 5import { Video, VideoDetails } from '@shared/models'
c2bd7a6f
C
6import {
7 buildServerDirectory,
8 cleanupTests,
9 doubleFollow,
10 execCLI,
11 flushAndRunMultipleServers,
12 getEnvCli,
13 getVideo,
14 makeRawRequest,
15 ServerInfo,
16 setAccessTokensToServers,
17 uploadVideoAndGetId,
18 waitJobs
19} from '../../../shared/extra-utils'
20import { HttpStatusCode } from '@shared/core-utils'
21
a0eeb45f
C
22async function testThumbnail (server: ServerInfo, videoId: number | string) {
23 const res = await getVideo(server.url, videoId)
24 const video: VideoDetails = res.body
25
26 const res1 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
27 expect(res1.body).to.not.have.lengthOf(0)
28
29 const res2 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
30 expect(res2.body).to.not.have.lengthOf(0)
31}
32
c2bd7a6f
C
33describe('Test regenerate thumbnails script', function () {
34 let servers: ServerInfo[]
35
36 let video1: Video
37 let video2: Video
38 let remoteVideo: Video
39
40 let thumbnail1Path: string
41 let thumbnailRemotePath: string
42
43 before(async function () {
44 this.timeout(60000)
45
46 servers = await flushAndRunMultipleServers(2)
47 await setAccessTokensToServers(servers)
48
49 await doubleFollow(servers[0], servers[1])
50
51 {
52 const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid
53 video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body))
54
55 thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath))
56
57 const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid
58 video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body))
59 }
60
61 {
62 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid
63 await waitJobs(servers)
64
65 remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body))
66
67 thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath))
68 }
69
70 await writeFile(thumbnail1Path, '')
71 await writeFile(thumbnailRemotePath, '')
72 })
73
74 it('Should have empty thumbnails', async function () {
75 {
76 const res = await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.OK_200)
77 expect(res.body).to.have.lengthOf(0)
78 }
79
80 {
81 const res = await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.OK_200)
82 expect(res.body).to.not.have.lengthOf(0)
83 }
84
85 {
86 const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200)
87 expect(res.body).to.have.lengthOf(0)
88 }
89 })
90
20373985 91 it('Should regenerate local thumbnails from the CLI', async function () {
c2bd7a6f
C
92 this.timeout(15000)
93
94 const env = getEnvCli(servers[0])
95 await execCLI(`${env} npm run regenerate-thumbnails`)
96 })
97
a0eeb45f
C
98 it('Should have generated new thumbnail files', async function () {
99 await testThumbnail(servers[0], video1.uuid)
100 await testThumbnail(servers[0], video2.uuid)
c2bd7a6f 101
a0eeb45f
C
102 const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200)
103 expect(res.body).to.have.lengthOf(0)
104 })
105
106 it('Should have deleted old thumbnail files', async function () {
107 {
108 await makeRawRequest(join(servers[0].url, video1.thumbnailPath), HttpStatusCode.NOT_FOUND_404)
c2bd7a6f
C
109 }
110
111 {
a0eeb45f 112 await makeRawRequest(join(servers[0].url, video2.thumbnailPath), HttpStatusCode.NOT_FOUND_404)
c2bd7a6f
C
113 }
114
115 {
116 const res = await makeRawRequest(join(servers[0].url, remoteVideo.thumbnailPath), HttpStatusCode.OK_200)
117 expect(res.body).to.have.lengthOf(0)
118 }
119 })
120
121 after(async function () {
122 await cleanupTests(servers)
123 })
124})