-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()
+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
+ }
+ },
+
+ video.state === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE
+ ? await buildMoveToObjectStorageJob({ video, previousVideoState: undefined })
+ : undefined,
+
+ video.state === VideoState.TO_TRANSCODE
+ ? await buildOptimizeOrMergeAudioJob({ video, videoFile, user })
+ : undefined
+ )