create-import-video-file-job.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. program
  7. .option('-v, --video [videoUUID]', 'Video UUID')
  8. .option('-i, --import [videoFile]', 'Video file')
  9. .description('Import a video file to replace an already uploaded file or to add a new resolution')
  10. .parse(process.argv)
  11. if (program['video'] === undefined || program['import'] === undefined) {
  12. console.error('All parameters are mandatory.')
  13. process.exit(-1)
  14. }
  15. run()
  16. .then(() => process.exit(0))
  17. .catch(err => {
  18. console.error(err)
  19. process.exit(-1)
  20. })
  21. async function run () {
  22. await initDatabaseModels(true)
  23. const video = await VideoModel.loadByUUIDWithFile(program['video'])
  24. if (!video) throw new Error('Video not found.')
  25. if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.')
  26. const dataInput = {
  27. videoUUID: video.uuid,
  28. filePath: resolve(program['import'])
  29. }
  30. await JobQueue.Instance.init()
  31. await JobQueue.Instance.createJob({ type: 'video-file-import', payload: dataInput })
  32. console.log('Import job for video %s created.', video.uuid)
  33. }