]>
Commit | Line | Data |
---|---|---|
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' | |
2 | registerTSPaths() | |
3 | ||
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, toCompleteUUID } from '@server/helpers/custom-validators/misc' | |
10 | ||
11 | program | |
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 | ||
17 | const options = program.opts() | |
18 | ||
19 | if (options.video === undefined || options.import === undefined) { | |
20 | console.error('All parameters are mandatory.') | |
21 | process.exit(-1) | |
22 | } | |
23 | ||
24 | run() | |
25 | .then(() => process.exit(0)) | |
26 | .catch(err => { | |
27 | console.error(err) | |
28 | process.exit(-1) | |
29 | }) | |
30 | ||
31 | async function run () { | |
32 | await initDatabaseModels(true) | |
33 | ||
34 | const uuid = toCompleteUUID(options.video) | |
35 | ||
36 | if (isUUIDValid(uuid) === false) { | |
37 | console.error('%s is not a valid video UUID.', options.video) | |
38 | return | |
39 | } | |
40 | ||
41 | const video = await VideoModel.load(uuid) | |
42 | if (!video) throw new Error('Video not found.') | |
43 | if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.') | |
44 | ||
45 | const dataInput = { | |
46 | videoUUID: video.uuid, | |
47 | filePath: resolve(options.import) | |
48 | } | |
49 | ||
50 | JobQueue.Instance.init() | |
51 | await JobQueue.Instance.createJobWithPromise({ type: 'video-file-import', payload: dataInput }) | |
52 | console.log('Import job for video %s created.', video.uuid) | |
53 | } |