1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
4 import { 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 import { isUUIDValid } from '@server/helpers/custom-validators/misc'
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')
17 const options = program.opts()
19 if (options.video === undefined || options.import === undefined) {
20 console.error('All parameters are mandatory.')
25 .then(() => process.exit(0))
31 async function run () {
32 await initDatabaseModels(true)
34 if (isUUIDValid(options.video) === false) {
35 console.error('%s is not a valid video UUID.', options.video)
39 const video = await VideoModel.load(options.video)
40 if (!video) throw new Error('Video not found.')
41 if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.')
44 videoUUID: video.uuid,
45 filePath: resolve(options.import)
48 JobQueue.Instance.init()
49 await JobQueue.Instance.createJobWithPromise({ type: 'video-file-import', payload: dataInput })
50 console.log('Import job for video %s created.', video.uuid)