]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/create-import-video-file-job.ts
Faster ci using compiled ts files
[github/Chocobozzz/PeerTube.git] / scripts / create-import-video-file-job.ts
CommitLineData
2aaa1a3f
C
1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths()
3
0138af92
FF
4import * as program from 'commander'
5import { resolve } from 'path'
6import { VideoModel } from '../server/models/video/video'
80fdaf06 7import { initDatabaseModels } from '../server/initializers/database'
0138af92 8import { JobQueue } from '../server/lib/job-queue'
9aeef9aa 9import { isUUIDValid } from '@server/helpers/custom-validators/misc'
0138af92
FF
10
11program
12 .option('-v, --video [videoUUID]', 'Video UUID')
13 .option('-i, --import [videoFile]', 'Video file')
14 .description('Import a video file to replace an already uploaded file or to add a new resolution')
15 .parse(process.argv)
16
ba5a8d89
C
17const options = program.opts()
18
19if (options.video === undefined || options.import === undefined) {
0138af92
FF
20 console.error('All parameters are mandatory.')
21 process.exit(-1)
22}
23
24run()
25 .then(() => process.exit(0))
26 .catch(err => {
27 console.error(err)
28 process.exit(-1)
29 })
30
31async function run () {
32 await initDatabaseModels(true)
33
9aeef9aa
C
34 if (isUUIDValid(options.video) === false) {
35 console.error('%s is not a valid video UUID.', options.video)
36 return
37 }
38
71d4af1e 39 const video = await VideoModel.load(options.video)
0138af92 40 if (!video) throw new Error('Video not found.')
28be8916 41 if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.')
0138af92
FF
42
43 const dataInput = {
44 videoUUID: video.uuid,
ba5a8d89 45 filePath: resolve(options.import)
0138af92
FF
46 }
47
71d4af1e 48 JobQueue.Instance.init()
a1587156 49 await JobQueue.Instance.createJobWithPromise({ type: 'video-file-import', payload: dataInput })
0138af92
FF
50 console.log('Import job for video %s created.', video.uuid)
51}