]>
Commit | Line | Data |
---|---|---|
0138af92 FF |
1 | import * as program from 'commander' |
2 | import { resolve } from 'path' | |
3 | import { VideoModel } from '../server/models/video/video' | |
4 | import { initDatabaseModels } from '../server/initializers' | |
5 | import { JobQueue } from '../server/lib/job-queue' | |
6 | ||
7 | program | |
8 | .option('-v, --video [videoUUID]', 'Video UUID') | |
9 | .option('-i, --import [videoFile]', 'Video file') | |
10 | .description('Import a video file to replace an already uploaded file or to add a new resolution') | |
11 | .parse(process.argv) | |
12 | ||
13 | if (program['video'] === undefined || program['import'] === undefined) { | |
14 | console.error('All parameters are mandatory.') | |
15 | process.exit(-1) | |
16 | } | |
17 | ||
18 | run() | |
19 | .then(() => process.exit(0)) | |
20 | .catch(err => { | |
21 | console.error(err) | |
22 | process.exit(-1) | |
23 | }) | |
24 | ||
25 | async function run () { | |
26 | await initDatabaseModels(true) | |
27 | ||
627621c1 | 28 | const video = await VideoModel.loadByUUIDWithFile(program['video']) |
0138af92 | 29 | if (!video) throw new Error('Video not found.') |
28be8916 | 30 | if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.') |
0138af92 FF |
31 | |
32 | const dataInput = { | |
33 | videoUUID: video.uuid, | |
34 | filePath: resolve(program['import']) | |
35 | } | |
36 | ||
37 | await JobQueue.Instance.init() | |
38 | await JobQueue.Instance.createJob({ type: 'video-file-import', payload: dataInput }) | |
39 | console.log('Import job for video %s created.', video.uuid) | |
40 | } |