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

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { registerTSPaths } from '../server/helpers/register-ts-paths'
  2. registerTSPaths()
  3. import * as program from 'commander'
  4. import { resolve } from 'path'
  5. import { VideoModel } from '../server/models/video/video'
  6. import { initDatabaseModels } from '../server/initializers/database'
  7. import { JobQueue } from '../server/lib/job-queue'
  8. program
  9. .option('-v, --video [videoUUID]', 'Video UUID')
  10. .option('-i, --import [videoFile]', 'Video file')
  11. .description('Import a video file to replace an already uploaded file or to add a new resolution')
  12. .parse(process.argv)
  13. if (program['video'] === undefined || program['import'] === undefined) {
  14. console.error('All parameters are mandatory.')
  15. process.exit(-1)
  16. }
  17. run()
  18. .then(() => process.exit(0))
  19. .catch(err => {
  20. console.error(err)
  21. process.exit(-1)
  22. })
  23. async function run () {
  24. await initDatabaseModels(true)
  25. const video = await VideoModel.loadByUUID(program['video'])
  26. if (!video) throw new Error('Video not found.')
  27. if (video.isOwned() === false) throw new Error('Cannot import files of a non owned video.')
  28. const dataInput = {
  29. videoUUID: video.uuid,
  30. filePath: resolve(program['import'])
  31. }
  32. await JobQueue.Instance.init()
  33. await JobQueue.Instance.createJobWithPromise({ type: 'video-file-import', payload: dataInput })
  34. console.log('Import job for video %s created.', video.uuid)
  35. }