-async function createTorrentAndSetInfoHashAsync (video: MVideo, fileArg: MVideoFile) {
- await createTorrentAndSetInfoHash(video, fileArg)
-
- // Refresh videoFile because the createTorrentAndSetInfoHash could be long
- const refreshedFile = await VideoFileModel.loadWithVideo(fileArg.id)
- // File does not exist anymore, remove the generated torrent
- if (!refreshedFile) return fileArg.removeTorrent()
-
- refreshedFile.infoHash = fileArg.infoHash
- refreshedFile.torrentFilename = fileArg.torrentFilename
-
- return refreshedFile.save()
-}
-
-function createTorrentFederate (video: MVideoFullLight, videoFile: MVideoFile) {
- // Create the torrent file in async way because it could be long
- return createTorrentAndSetInfoHashAsync(video, videoFile)
- .catch(err => logger.error('Cannot create torrent file for video %s', video.url, { err, ...lTags(video.uuid) }))
- .then(() => VideoModel.loadAndPopulateAccountAndServerAndTags(video.id))
- .then(refreshedVideo => {
- if (!refreshedVideo) return
+async function addVideoJobsAfterUpload (video: MVideoFullLight, videoFile: MVideoFile, user: MUserId) {
+ return JobQueue.Instance.createSequentialJobFlow(
+ {
+ type: 'manage-video-torrent' as 'manage-video-torrent',
+ payload: {
+ videoId: video.id,
+ videoFileId: videoFile.id,
+ action: 'create'
+ }
+ },
+ {
+ type: 'federate-video' as 'federate-video',
+ payload: {
+ videoUUID: video.uuid,
+ isNewVideo: true
+ }
+ },