diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/core-utils/miscs/index.ts | 1 | ||||
-rw-r--r-- | shared/core-utils/miscs/regexp.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/server/server.ts | 18 | ||||
-rw-r--r-- | shared/extra-utils/server/servers-command.ts | 9 | ||||
-rw-r--r-- | shared/extra-utils/videos/streaming-playlists.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 89 |
6 files changed, 79 insertions, 43 deletions
diff --git a/shared/core-utils/miscs/index.ts b/shared/core-utils/miscs/index.ts index afd147f24..7764e69ad 100644 --- a/shared/core-utils/miscs/index.ts +++ b/shared/core-utils/miscs/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './date' | 1 | export * from './date' |
2 | export * from './miscs' | 2 | export * from './miscs' |
3 | export * from './types' | 3 | export * from './types' |
4 | export * from './regexp' | ||
diff --git a/shared/core-utils/miscs/regexp.ts b/shared/core-utils/miscs/regexp.ts new file mode 100644 index 000000000..862b8e00f --- /dev/null +++ b/shared/core-utils/miscs/regexp.ts | |||
@@ -0,0 +1 @@ | |||
export const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' | |||
diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts index 5bdcbac52..d37a7f39c 100644 --- a/shared/extra-utils/server/server.ts +++ b/shared/extra-utils/server/server.ts | |||
@@ -3,7 +3,7 @@ import { copy } from 'fs-extra' | |||
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { root } from '@server/helpers/core-utils' | 4 | import { root } from '@server/helpers/core-utils' |
5 | import { randomInt } from '../../core-utils/miscs/miscs' | 5 | import { randomInt } from '../../core-utils/miscs/miscs' |
6 | import { VideoChannel } from '../../models/videos' | 6 | import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos' |
7 | import { BulkCommand } from '../bulk' | 7 | import { BulkCommand } from '../bulk' |
8 | import { CLICommand } from '../cli' | 8 | import { CLICommand } from '../cli' |
9 | import { CustomPagesCommand } from '../custom-pages' | 9 | import { CustomPagesCommand } from '../custom-pages' |
@@ -75,19 +75,9 @@ export class PeerTubeServer { | |||
75 | 75 | ||
76 | channel?: VideoChannel | 76 | channel?: VideoChannel |
77 | 77 | ||
78 | video?: { | 78 | video?: Video |
79 | id: number | 79 | videoCreated?: VideoCreateResult |
80 | uuid: string | 80 | videoDetails?: VideoDetails |
81 | shortUUID: string | ||
82 | name?: string | ||
83 | url?: string | ||
84 | |||
85 | account?: { | ||
86 | name: string | ||
87 | } | ||
88 | |||
89 | embedPath?: string | ||
90 | } | ||
91 | 81 | ||
92 | videos?: { id: number, uuid: string }[] | 82 | videos?: { id: number, uuid: string }[] |
93 | } | 83 | } |
diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts index a78921f2a..441c728c1 100644 --- a/shared/extra-utils/server/servers-command.ts +++ b/shared/extra-utils/server/servers-command.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { exec } from 'child_process' | 1 | import { exec } from 'child_process' |
2 | import { copy, ensureDir, readFile, remove } from 'fs-extra' | 2 | import { copy, ensureDir, readFile, remove } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { basename } from 'path/posix' | ||
4 | import { root } from '@server/helpers/core-utils' | 5 | import { root } from '@server/helpers/core-utils' |
5 | import { HttpStatusCode } from '@shared/models' | 6 | import { HttpStatusCode } from '@shared/models' |
6 | import { getFileSize, isGithubCI, wait } from '../miscs' | 7 | import { getFileSize, isGithubCI, wait } from '../miscs' |
@@ -72,6 +73,14 @@ export class ServersCommand extends AbstractCommand { | |||
72 | return join(root(), 'test' + this.server.internalServerNumber, directory) | 73 | return join(root(), 'test' + this.server.internalServerNumber, directory) |
73 | } | 74 | } |
74 | 75 | ||
76 | buildWebTorrentFilePath (fileUrl: string) { | ||
77 | return this.buildDirectory(join('videos', basename(fileUrl))) | ||
78 | } | ||
79 | |||
80 | buildFragmentedFilePath (videoUUID: string, fileUrl: string) { | ||
81 | return this.buildDirectory(join('streaming-playlists', 'hls', videoUUID, basename(fileUrl))) | ||
82 | } | ||
83 | |||
75 | async getServerFileSize (subPath: string) { | 84 | async getServerFileSize (subPath: string) { |
76 | const path = this.server.servers.buildDirectory(subPath) | 85 | const path = this.server.servers.buildDirectory(subPath) |
77 | 86 | ||
diff --git a/shared/extra-utils/videos/streaming-playlists.ts b/shared/extra-utils/videos/streaming-playlists.ts index 1ae3fefc1..db40c27be 100644 --- a/shared/extra-utils/videos/streaming-playlists.ts +++ b/shared/extra-utils/videos/streaming-playlists.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { expect } from 'chai' | 1 | import { expect } from 'chai' |
2 | import { basename } from 'path' | ||
2 | import { sha256 } from '@server/helpers/core-utils' | 3 | import { sha256 } from '@server/helpers/core-utils' |
3 | import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' | 4 | import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' |
4 | import { PeerTubeServer } from '../server' | 5 | import { PeerTubeServer } from '../server' |
@@ -16,7 +17,8 @@ async function checkSegmentHash (options: { | |||
16 | 17 | ||
17 | const playlist = await command.get({ url: `${baseUrlPlaylist}/${videoUUID}/${resolution}.m3u8` }) | 18 | const playlist = await command.get({ url: `${baseUrlPlaylist}/${videoUUID}/${resolution}.m3u8` }) |
18 | 19 | ||
19 | const videoName = `${videoUUID}-${resolution}-fragmented.mp4` | 20 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) |
21 | const videoName = basename(file.fileUrl) | ||
20 | 22 | ||
21 | const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) | 23 | const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) |
22 | 24 | ||
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 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { pathExists, readdir } from 'fs-extra' | 4 | import { pathExists, readdir } from 'fs-extra' |
5 | import { join } from 'path' | 5 | import { basename, join } from 'path' |
6 | import { getLowercaseExtension } from '@server/helpers/core-utils' | 6 | import { getLowercaseExtension } from '@server/helpers/core-utils' |
7 | import { HttpStatusCode } from '@shared/models' | 7 | import { uuidRegex } from '@shared/core-utils' |
8 | import { HttpStatusCode, VideoCaption, VideoDetails } from '@shared/models' | ||
8 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | 9 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' |
9 | import { dateIsValid, testImage, webtorrentAdd } from '../miscs' | 10 | import { dateIsValid, testImage, webtorrentAdd } from '../miscs' |
10 | import { makeRawRequest } from '../requests/requests' | 11 | import { makeRawRequest } from '../requests/requests' |
@@ -12,33 +13,66 @@ import { waitJobs } from '../server' | |||
12 | import { PeerTubeServer } from '../server/server' | 13 | import { PeerTubeServer } from '../server/server' |
13 | import { VideoEdit } from './videos-command' | 14 | import { VideoEdit } from './videos-command' |
14 | 15 | ||
15 | async function checkVideoFilesWereRemoved ( | 16 | async 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 | ||
70 | async 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 | |||
42 | function checkUploadVideoParam ( | 76 | function 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 | } |