]>
Commit | Line | Data |
---|---|---|
2aaa1a3f C |
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' |
2 | registerTSPaths() | |
3 | ||
0138af92 FF |
4 | import * as program from 'commander' |
5 | import { resolve } from 'path' | |
6 | import { VideoModel } from '../server/models/video/video' | |
80fdaf06 | 7 | import { initDatabaseModels } from '../server/initializers/database' |
0138af92 | 8 | import { JobQueue } from '../server/lib/job-queue' |
9aeef9aa | 9 | import { isUUIDValid } from '@server/helpers/custom-validators/misc' |
0138af92 FF |
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 | ||
ba5a8d89 C |
17 | const options = program.opts() |
18 | ||
19 | if (options.video === undefined || options.import === undefined) { | |
0138af92 FF |
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 | ||
9aeef9aa C |
34 | if (isUUIDValid(options.video) === false) { |
35 | console.error('%s is not a valid video UUID.', options.video) | |
36 | return | |
37 | } | |
38 | ||
ba5a8d89 | 39 | const video = await VideoModel.loadByUUID(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 | ||
48 | await 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 | } |