diff options
author | Florent Fayolle <florent.fayolle69@gmail.com> | 2018-06-02 21:39:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-07 08:57:48 +0200 |
commit | 0138af9237b77dd7d3a49260d164193b4048de84 (patch) | |
tree | 5a377c7577cd99d5b324967187e10cd9fcc81383 /scripts/create-import-video-file-job.ts | |
parent | 157b62b1f4450c32bb7383ccacbea555ec607013 (diff) | |
download | PeerTube-0138af9237b77dd7d3a49260d164193b4048de84.tar.gz PeerTube-0138af9237b77dd7d3a49260d164193b4048de84.tar.zst PeerTube-0138af9237b77dd7d3a49260d164193b4048de84.zip |
Add create-import-video-file-job command
Diffstat (limited to 'scripts/create-import-video-file-job.ts')
-rw-r--r-- | scripts/create-import-video-file-job.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/scripts/create-import-video-file-job.ts b/scripts/create-import-video-file-job.ts new file mode 100644 index 000000000..a2f4f38f2 --- /dev/null +++ b/scripts/create-import-video-file-job.ts | |||
@@ -0,0 +1,39 @@ | |||
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 | |||
28 | const video = await VideoModel.loadByUUID(program['video']) | ||
29 | if (!video) throw new Error('Video not found.') | ||
30 | |||
31 | const dataInput = { | ||
32 | videoUUID: video.uuid, | ||
33 | filePath: resolve(program['import']) | ||
34 | } | ||
35 | |||
36 | await JobQueue.Instance.init() | ||
37 | await JobQueue.Instance.createJob({ type: 'video-file-import', payload: dataInput }) | ||
38 | console.log('Import job for video %s created.', video.uuid) | ||
39 | } | ||