+
+async function afterImportSuccess (options: {
+ videoImport: MVideoImport
+ video: MVideoFullLight
+ videoFile: MVideoFile
+ user: MUserId
+}) {
+ const { video, videoFile, videoImport, user } = options
+
+ Notifier.Instance.notifyOnFinishedVideoImport({ videoImport: Object.assign(videoImport, { Video: video }), success: true })
+
+ if (video.isBlacklisted()) {
+ const videoBlacklist = Object.assign(video.VideoBlacklist, { Video: video })
+
+ Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist)
+ } else {
+ Notifier.Instance.notifyOnNewVideoIfNeeded(video)
+ }
+
+ if (video.state === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) {
+ await JobQueue.Instance.createJob(
+ await buildMoveToObjectStorageJob({ video, previousVideoState: VideoState.TO_IMPORT })
+ )
+ return
+ }
+
+ if (video.state === VideoState.TO_TRANSCODE) { // Create transcoding jobs?
+ await createOptimizeOrMergeAudioJobs({ video, videoFile, isNewVideo: true, user })
+ }
+}
+
+async function onImportError (err: Error, tempVideoPath: string, videoImport: MVideoImportVideo) {
+ try {
+ if (tempVideoPath) await remove(tempVideoPath)
+ } catch (errUnlink) {
+ logger.warn('Cannot cleanup files after a video import error.', { err: errUnlink })
+ }
+
+ videoImport.error = err.message
+ if (videoImport.state !== VideoImportState.REJECTED) {
+ videoImport.state = VideoImportState.FAILED
+ }
+ await videoImport.save()
+
+ Notifier.Instance.notifyOnFinishedVideoImport({ videoImport, success: false })
+}