aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/videos/videos.ts')
-rw-r--r--shared/extra-utils/videos/videos.ts89
1 files changed, 61 insertions, 28 deletions
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index 9a9bfb3cf..a1d2ba0fc 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -2,9 +2,10 @@
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path' 5import { basename, join } from 'path'
6import { getLowercaseExtension } from '@server/helpers/core-utils' 6import { getLowercaseExtension } from '@server/helpers/core-utils'
7import { HttpStatusCode } from '@shared/models' 7import { uuidRegex } from '@shared/core-utils'
8import { HttpStatusCode, VideoCaption, VideoDetails } from '@shared/models'
8import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' 9import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
9import { dateIsValid, testImage, webtorrentAdd } from '../miscs' 10import { dateIsValid, testImage, webtorrentAdd } from '../miscs'
10import { makeRawRequest } from '../requests/requests' 11import { makeRawRequest } from '../requests/requests'
@@ -12,33 +13,66 @@ import { waitJobs } from '../server'
12import { PeerTubeServer } from '../server/server' 13import { PeerTubeServer } from '../server/server'
13import { VideoEdit } from './videos-command' 14import { VideoEdit } from './videos-command'
14 15
15async function checkVideoFilesWereRemoved ( 16async function checkVideoFilesWereRemoved (options: {
16 videoUUID: string, 17 server: PeerTubeServer
17 server: PeerTubeServer, 18 video: VideoDetails
18 directories = [ 19 captions?: VideoCaption[]
19 'redundancy', 20 onlyVideoFiles?: boolean // default false
20 'videos', 21}) {
21 'thumbnails', 22 const { video, server, captions = [], onlyVideoFiles = false } = options
22 'torrents', 23
23 'previews', 24 const webtorrentFiles = video.files || []
24 'captions', 25 const hlsFiles = video.streamingPlaylists[0]?.files || []
25 join('playlists', 'hls'), 26
26 join('redundancy', 'hls') 27 const thumbnailName = basename(video.thumbnailPath)
27 ] 28 const previewName = basename(video.previewPath)
28) { 29
29 for (const directory of directories) { 30 const torrentNames = webtorrentFiles.concat(hlsFiles).map(f => basename(f.torrentUrl))
31
32 const captionNames = captions.map(c => basename(c.captionPath))
33
34 const webtorrentFilenames = webtorrentFiles.map(f => basename(f.fileUrl))
35 const hlsFilenames = hlsFiles.map(f => basename(f.fileUrl))
36
37 let directories: { [ directory: string ]: string[] } = {
38 videos: webtorrentFilenames,
39 redundancy: webtorrentFilenames,
40 [join('playlists', 'hls')]: hlsFilenames,
41 [join('redundancy', 'hls')]: hlsFilenames
42 }
43
44 if (onlyVideoFiles !== true) {
45 directories = {
46 ...directories,
47
48 thumbnails: [ thumbnailName ],
49 previews: [ previewName ],
50 torrents: torrentNames,
51 captions: captionNames
52 }
53 }
54
55 for (const directory of Object.keys(directories)) {
30 const directoryPath = server.servers.buildDirectory(directory) 56 const directoryPath = server.servers.buildDirectory(directory)
31 57
32 const directoryExists = await pathExists(directoryPath) 58 const directoryExists = await pathExists(directoryPath)
33 if (directoryExists === false) continue 59 if (directoryExists === false) continue
34 60
35 const files = await readdir(directoryPath) 61 const existingFiles = await readdir(directoryPath)
36 for (const file of files) { 62 for (const existingFile of existingFiles) {
37 expect(file, `File ${file} should not exist in ${directoryPath}`).to.not.contain(videoUUID) 63 for (const shouldNotExist of directories[directory]) {
64 expect(existingFile, `File ${existingFile} should not exist in ${directoryPath}`).to.not.contain(shouldNotExist)
65 }
38 } 66 }
39 } 67 }
40} 68}
41 69
70async function saveVideoInServers (servers: PeerTubeServer[], uuid: string) {
71 for (const server of servers) {
72 server.store.videoDetails = await server.videos.get({ id: uuid })
73 }
74}
75
42function checkUploadVideoParam ( 76function checkUploadVideoParam (
43 server: PeerTubeServer, 77 server: PeerTubeServer,
44 token: string, 78 token: string,
@@ -156,18 +190,16 @@ async function completeVideoCheck (
156 190
157 expect(file.magnetUri).to.have.lengthOf.above(2) 191 expect(file.magnetUri).to.have.lengthOf.above(2)
158 192
159 expect(file.torrentDownloadUrl).to.equal(`http://${host}/download/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`) 193 expect(file.torrentDownloadUrl).to.match(new RegExp(`http://${host}/download/torrents/${uuidRegex}-${file.resolution.id}.torrent`))
160 expect(file.torrentUrl).to.equal(`http://${host}/lazy-static/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`) 194 expect(file.torrentUrl).to.match(new RegExp(`http://${host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}.torrent`))
161 195
162 expect(file.fileUrl).to.equal(`http://${originHost}/static/webseed/${videoDetails.uuid}-${file.resolution.id}${extension}`) 196 expect(file.fileUrl).to.match(new RegExp(`http://${originHost}/static/webseed/${uuidRegex}-${file.resolution.id}${extension}`))
163 expect(file.fileDownloadUrl).to.equal(`http://${originHost}/download/videos/${videoDetails.uuid}-${file.resolution.id}${extension}`) 197 expect(file.fileDownloadUrl).to.match(new RegExp(`http://${originHost}/download/videos/${uuidRegex}-${file.resolution.id}${extension}`))
164 198
165 await Promise.all([ 199 await Promise.all([
166 makeRawRequest(file.torrentUrl, 200), 200 makeRawRequest(file.torrentUrl, 200),
167 makeRawRequest(file.torrentDownloadUrl, 200), 201 makeRawRequest(file.torrentDownloadUrl, 200),
168 makeRawRequest(file.metadataUrl, 200), 202 makeRawRequest(file.metadataUrl, 200)
169 // Backward compatibility
170 makeRawRequest(`http://${originHost}/static/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`, 200)
171 ]) 203 ])
172 204
173 expect(file.resolution.id).to.equal(attributeFile.resolution) 205 expect(file.resolution.id).to.equal(attributeFile.resolution)
@@ -215,5 +247,6 @@ export {
215 checkUploadVideoParam, 247 checkUploadVideoParam,
216 completeVideoCheck, 248 completeVideoCheck,
217 uploadRandomVideoOnServers, 249 uploadRandomVideoOnServers,
218 checkVideoFilesWereRemoved 250 checkVideoFilesWereRemoved,
251 saveVideoInServers
219} 252}