]>
Commit | Line | Data |
---|---|---|
2aaa1a3f C |
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' |
2 | registerTSPaths() | |
3 | ||
8cc61201 | 4 | import { program } from 'commander' |
0138af92 FF |
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' |
c186a67f | 9 | import { isUUIDValid, toCompleteUUID } 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 | ||
c186a67f C |
34 | const uuid = toCompleteUUID(options.video) |
35 | ||
36 | if (isUUIDValid(uuid) === false) { | |
9aeef9aa C |
37 | console.error('%s is not a valid video UUID.', options.video) |
38 | return | |
39 | } | |
40 | ||
c186a67f | 41 | const video = await VideoModel.load(uuid) |
0138af92 | 42 | if (!video) throw new Error('Video not found.') |
28be8916 | 43 | if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.') |
0138af92 FF |
44 | |
45 | const dataInput = { | |
46 | videoUUID: video.uuid, | |
ba5a8d89 | 47 | filePath: resolve(options.import) |
0138af92 FF |
48 | } |
49 | ||
71d4af1e | 50 | JobQueue.Instance.init() |
a1587156 | 51 | await JobQueue.Instance.createJobWithPromise({ type: 'video-file-import', payload: dataInput }) |
0138af92 FF |
52 | console.log('Import job for video %s created.', video.uuid) |
53 | } |