1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { join } from 'path'
4 import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
5 import { HttpStatusCode, VideoDetails } from '@shared/models'
13 setAccessTokensToServers,
15 } from '@shared/server-commands'
16 import { checkDirectoryIsEmpty, expectStartWith } from '../shared'
18 async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
19 for (const file of video.files) {
20 const start = inObjectStorage
21 ? ObjectStorageCommand.getMockWebTorrentBaseUrl()
24 expectStartWith(file.fileUrl, start)
26 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
29 const start = inObjectStorage
30 ? ObjectStorageCommand.getMockPlaylistBaseUrl()
33 const hls = video.streamingPlaylists[0]
34 expectStartWith(hls.playlistUrl, start)
35 expectStartWith(hls.segmentsSha256Url, start)
37 for (const file of hls.files) {
38 expectStartWith(file.fileUrl, start)
40 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
44 describe('Test create move video storage job', function () {
45 if (areMockObjectStorageTestsDisabled()) return
47 let servers: PeerTubeServer[] = []
48 const uuids: string[] = []
50 before(async function () {
53 // Run server 2 to have transcoding enabled
54 servers = await createMultipleServers(2)
55 await setAccessTokensToServers(servers)
57 await doubleFollow(servers[0], servers[1])
59 await ObjectStorageCommand.prepareDefaultMockBuckets()
61 await servers[0].config.enableTranscoding()
63 for (let i = 0; i < 3; i++) {
64 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
68 await waitJobs(servers)
70 await servers[0].kill()
71 await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
74 it('Should move only one file', async function () {
77 const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}`
78 await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig())
79 await waitJobs(servers)
81 for (const server of servers) {
82 const video = await server.videos.get({ id: uuids[1] })
84 await checkFiles(servers[0], video, true)
86 for (const id of [ uuids[0], uuids[2] ]) {
87 const video = await server.videos.get({ id })
89 await checkFiles(servers[0], video, false)
94 it('Should move all files', async function () {
97 const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos`
98 await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig())
99 await waitJobs(servers)
101 for (const server of servers) {
102 for (const id of [ uuids[0], uuids[2] ]) {
103 const video = await server.videos.get({ id })
105 await checkFiles(servers[0], video, true)
110 it('Should not have files on disk anymore', async function () {
111 await checkDirectoryIsEmpty(servers[0], 'videos', [ 'private' ])
112 await checkDirectoryIsEmpty(servers[0], join('videos', 'private'))
114 await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls'), [ 'private' ])
115 await checkDirectoryIsEmpty(servers[0], join('streaming-playlists', 'hls', 'private'))
118 after(async function () {
119 await cleanupTests(servers)