]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/create-import-video-file-job.ts
Translated using Weblate (Turkish)
[github/Chocobozzz/PeerTube.git] / scripts / create-import-video-file-job.ts
CommitLineData
2aaa1a3f
C
1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths()
3
0138af92
FF
4import * as program from 'commander'
5import { resolve } from 'path'
6import { VideoModel } from '../server/models/video/video'
80fdaf06 7import { initDatabaseModels } from '../server/initializers/database'
0138af92
FF
8import { JobQueue } from '../server/lib/job-queue'
9
10program
11 .option('-v, --video [videoUUID]', 'Video UUID')
12 .option('-i, --import [videoFile]', 'Video file')
13 .description('Import a video file to replace an already uploaded file or to add a new resolution')
14 .parse(process.argv)
15
ba5a8d89
C
16const options = program.opts()
17
18if (options.video === undefined || options.import === undefined) {
0138af92
FF
19 console.error('All parameters are mandatory.')
20 process.exit(-1)
21}
22
23run()
24 .then(() => process.exit(0))
25 .catch(err => {
26 console.error(err)
27 process.exit(-1)
28 })
29
30async function run () {
31 await initDatabaseModels(true)
32
ba5a8d89 33 const video = await VideoModel.loadByUUID(options.video)
0138af92 34 if (!video) throw new Error('Video not found.')
28be8916 35 if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.')
0138af92
FF
36
37 const dataInput = {
38 videoUUID: video.uuid,
ba5a8d89 39 filePath: resolve(options.import)
0138af92
FF
40 }
41
42 await JobQueue.Instance.init()
a1587156 43 await JobQueue.Instance.createJobWithPromise({ type: 'video-file-import', payload: dataInput })
0138af92
FF
44 console.log('Import job for video %s created.', video.uuid)
45}