1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
6 areObjectStorageTestsDisabled,
14 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { HttpStatusCode, VideoDetails } from '@shared/models'
19 async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
20 for (const file of video.files) {
21 const start = inObjectStorage
22 ? ObjectStorageCommand.getWebTorrentBaseUrl()
25 expectStartWith(file.fileUrl, start)
27 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
30 const start = inObjectStorage
31 ? ObjectStorageCommand.getPlaylistBaseUrl()
34 const hls = video.streamingPlaylists[0]
35 expectStartWith(hls.playlistUrl, start)
36 expectStartWith(hls.segmentsSha256Url, start)
38 for (const file of hls.files) {
39 expectStartWith(file.fileUrl, start)
41 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
45 describe('Test create move video storage job', function () {
46 if (areObjectStorageTestsDisabled()) return
48 let servers: PeerTubeServer[] = []
49 const uuids: string[] = []
51 before(async function () {
54 // Run server 2 to have transcoding enabled
55 servers = await createMultipleServers(2)
56 await setAccessTokensToServers(servers)
58 await doubleFollow(servers[0], servers[1])
60 await ObjectStorageCommand.prepareDefaultBuckets()
62 await servers[0].config.enableTranscoding()
64 for (let i = 0; i < 3; i++) {
65 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
69 await waitJobs(servers)
71 await servers[0].kill()
72 await servers[0].run(ObjectStorageCommand.getDefaultConfig())
75 it('Should move only one file', async function () {
78 const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}`
79 await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultConfig())
80 await waitJobs(servers)
82 for (const server of servers) {
83 const video = await server.videos.get({ id: uuids[1] })
85 await checkFiles(servers[0], video, true)
87 for (const id of [ uuids[0], uuids[2] ]) {
88 const video = await server.videos.get({ id })
90 await checkFiles(servers[0], video, false)
95 it('Should move all files', async function () {
98 const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos`
99 await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultConfig())
100 await waitJobs(servers)
102 for (const server of servers) {
103 for (const id of [ uuids[0], uuids[2] ]) {
104 const video = await server.videos.get({ id })
106 await checkFiles(servers[0], video, true)
111 after(async function () {
112 await cleanupTests(servers)