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