aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-17 11:06:10 +0200
committerChocobozzz <me@florianbigard.com>2021-08-17 11:06:10 +0200
commitc186a67f90203af6bfa434f026efdc99193bcd65 (patch)
tree54e715f1afba3aaa14d6448fdbc14d699b7ae775
parent66a7fc947321b923fa1e7182202e03d0e21ffb3e (diff)
downloadPeerTube-c186a67f90203af6bfa434f026efdc99193bcd65.tar.gz
PeerTube-c186a67f90203af6bfa434f026efdc99193bcd65.tar.zst
PeerTube-c186a67f90203af6bfa434f026efdc99193bcd65.zip
Support short uuid for scripts
-rw-r--r--scripts/create-import-video-file-job.ts8
-rwxr-xr-xscripts/create-transcoding-job.ts8
-rw-r--r--server/tests/cli/create-import-video-file-job.ts16
-rw-r--r--server/tests/cli/create-transcoding-job.ts11
4 files changed, 26 insertions, 17 deletions
diff --git a/scripts/create-import-video-file-job.ts b/scripts/create-import-video-file-job.ts
index a3a35bc10..726f51ccf 100644
--- a/scripts/create-import-video-file-job.ts
+++ b/scripts/create-import-video-file-job.ts
@@ -6,7 +6,7 @@ import { resolve } from 'path'
6import { VideoModel } from '../server/models/video/video' 6import { VideoModel } from '../server/models/video/video'
7import { initDatabaseModels } from '../server/initializers/database' 7import { initDatabaseModels } from '../server/initializers/database'
8import { JobQueue } from '../server/lib/job-queue' 8import { JobQueue } from '../server/lib/job-queue'
9import { isUUIDValid } from '@server/helpers/custom-validators/misc' 9import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc'
10 10
11program 11program
12 .option('-v, --video [videoUUID]', 'Video UUID') 12 .option('-v, --video [videoUUID]', 'Video UUID')
@@ -31,12 +31,14 @@ run()
31async function run () { 31async function run () {
32 await initDatabaseModels(true) 32 await initDatabaseModels(true)
33 33
34 if (isUUIDValid(options.video) === false) { 34 const uuid = toCompleteUUID(options.video)
35
36 if (isUUIDValid(uuid) === false) {
35 console.error('%s is not a valid video UUID.', options.video) 37 console.error('%s is not a valid video UUID.', options.video)
36 return 38 return
37 } 39 }
38 40
39 const video = await VideoModel.load(options.video) 41 const video = await VideoModel.load(uuid)
40 if (!video) throw new Error('Video not found.') 42 if (!video) throw new Error('Video not found.')
41 if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.') 43 if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.')
42 44
diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts
index 0bb9bfeab..30846cd15 100755
--- a/scripts/create-transcoding-job.ts
+++ b/scripts/create-transcoding-job.ts
@@ -8,7 +8,7 @@ import { JobQueue } from '../server/lib/job-queue'
8import { computeResolutionsToTranscode } from '@server/helpers/ffprobe-utils' 8import { computeResolutionsToTranscode } from '@server/helpers/ffprobe-utils'
9import { VideoState, VideoTranscodingPayload } from '@shared/models' 9import { VideoState, VideoTranscodingPayload } from '@shared/models'
10import { CONFIG } from '@server/initializers/config' 10import { CONFIG } from '@server/initializers/config'
11import { isUUIDValid } from '@server/helpers/custom-validators/misc' 11import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc'
12import { addTranscodingJob } from '@server/lib/video' 12import { addTranscodingJob } from '@server/lib/video'
13 13
14program 14program
@@ -39,12 +39,14 @@ run()
39async function run () { 39async function run () {
40 await initDatabaseModels(true) 40 await initDatabaseModels(true)
41 41
42 if (isUUIDValid(options.video) === false) { 42 const uuid = toCompleteUUID(options.video)
43
44 if (isUUIDValid(uuid) === false) {
43 console.error('%s is not a valid video UUID.', options.video) 45 console.error('%s is not a valid video UUID.', options.video)
44 return 46 return
45 } 47 }
46 48
47 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(options.video) 49 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(uuid)
48 if (!video) throw new Error('Video not found.') 50 if (!video) throw new Error('Video not found.')
49 51
50 const dataInput: VideoTranscodingPayload[] = [] 52 const dataInput: VideoTranscodingPayload[] = []
diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts
index 9f1b57a2e..01817216e 100644
--- a/server/tests/cli/create-import-video-file-job.ts
+++ b/server/tests/cli/create-import-video-file-job.ts
@@ -37,7 +37,7 @@ async function checkFiles (video: VideoDetails, objectStorage: boolean) {
37} 37}
38 38
39function runTests (objectStorage: boolean) { 39function runTests (objectStorage: boolean) {
40 let video1UUID: string 40 let video1ShortId: string
41 let video2UUID: string 41 let video2UUID: string
42 42
43 let servers: PeerTubeServer[] = [] 43 let servers: PeerTubeServer[] = []
@@ -59,8 +59,8 @@ function runTests (objectStorage: boolean) {
59 59
60 // Upload two videos for our needs 60 // Upload two videos for our needs
61 { 61 {
62 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video1' } }) 62 const { shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
63 video1UUID = uuid 63 video1ShortId = shortUUID
64 } 64 }
65 65
66 { 66 {
@@ -72,7 +72,7 @@ function runTests (objectStorage: boolean) {
72 }) 72 })
73 73
74 it('Should run a import job on video 1 with a lower resolution', async function () { 74 it('Should run a import job on video 1 with a lower resolution', async function () {
75 const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm` 75 const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short-480.webm`
76 await servers[0].cli.execWithEnv(command) 76 await servers[0].cli.execWithEnv(command)
77 77
78 await waitJobs(servers) 78 await waitJobs(servers)
@@ -81,8 +81,8 @@ function runTests (objectStorage: boolean) {
81 const { data: videos } = await server.videos.list() 81 const { data: videos } = await server.videos.list()
82 expect(videos).to.have.lengthOf(2) 82 expect(videos).to.have.lengthOf(2)
83 83
84 const video = videos.find(({ uuid }) => uuid === video1UUID) 84 const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
85 const videoDetails = await server.videos.get({ id: video.uuid }) 85 const videoDetails = await server.videos.get({ id: video.shortUUID })
86 86
87 expect(videoDetails.files).to.have.lengthOf(2) 87 expect(videoDetails.files).to.have.lengthOf(2)
88 const [ originalVideo, transcodedVideo ] = videoDetails.files 88 const [ originalVideo, transcodedVideo ] = videoDetails.files
@@ -118,7 +118,7 @@ function runTests (objectStorage: boolean) {
118 }) 118 })
119 119
120 it('Should run a import job on video 2 with the same resolution and the same extension', async function () { 120 it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
121 const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm` 121 const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short2.webm`
122 await servers[0].cli.execWithEnv(command) 122 await servers[0].cli.execWithEnv(command)
123 123
124 await waitJobs(servers) 124 await waitJobs(servers)
@@ -127,7 +127,7 @@ function runTests (objectStorage: boolean) {
127 const { data: videos } = await server.videos.list() 127 const { data: videos } = await server.videos.list()
128 expect(videos).to.have.lengthOf(2) 128 expect(videos).to.have.lengthOf(2)
129 129
130 const video = videos.find(({ uuid }) => uuid === video1UUID) 130 const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
131 const videoDetails = await server.videos.get({ id: video.uuid }) 131 const videoDetails = await server.videos.get({ id: video.uuid })
132 132
133 expect(videoDetails.files).to.have.lengthOf(2) 133 expect(videoDetails.files).to.have.lengthOf(2)
diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts
index 3313a492f..3fd624091 100644
--- a/server/tests/cli/create-transcoding-job.ts
+++ b/server/tests/cli/create-transcoding-job.ts
@@ -52,8 +52,13 @@ function runTests (objectStorage: boolean) {
52 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets() 52 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
53 53
54 for (let i = 1; i <= 5; i++) { 54 for (let i = 1; i <= 5; i++) {
55 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } }) 55 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
56 videosUUID.push(uuid) 56
57 if (i > 2) {
58 videosUUID.push(uuid)
59 } else {
60 videosUUID.push(shortUUID)
61 }
57 } 62 }
58 63
59 await waitJobs(servers) 64 await waitJobs(servers)
@@ -88,7 +93,7 @@ function runTests (objectStorage: boolean) {
88 for (const video of data) { 93 for (const video of data) {
89 const videoDetails = await server.videos.get({ id: video.uuid }) 94 const videoDetails = await server.videos.get({ id: video.uuid })
90 95
91 if (video.uuid === videosUUID[1]) { 96 if (video.shortUUID === videosUUID[1] || video.uuid === videosUUID[1]) {
92 expect(videoDetails.files).to.have.lengthOf(4) 97 expect(videoDetails.files).to.have.lengthOf(4)
93 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) 98 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
94 99