aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/videos.ts22
-rw-r--r--server/lib/job-queue/handlers/video-file.ts18
-rw-r--r--server/lib/job-queue/handlers/video-import.ts7
3 files changed, 24 insertions, 23 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 5794988a5..893768769 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -204,19 +204,17 @@ async function updateVideoFromAP (options: {
204 overrideTo?: string[] 204 overrideTo?: string[]
205}) { 205}) {
206 logger.debug('Updating remote video "%s".', options.videoObject.uuid) 206 logger.debug('Updating remote video "%s".', options.videoObject.uuid)
207
207 let videoFieldsSave: any 208 let videoFieldsSave: any
209 const wasPrivateVideo = options.video.privacy === VideoPrivacy.PRIVATE
210 const wasUnlistedVideo = options.video.privacy === VideoPrivacy.UNLISTED
208 211
209 try { 212 try {
210 await sequelizeTypescript.transaction(async t => { 213 await sequelizeTypescript.transaction(async t => {
211 const sequelizeOptions = { 214 const sequelizeOptions = { transaction: t }
212 transaction: t
213 }
214 215
215 videoFieldsSave = options.video.toJSON() 216 videoFieldsSave = options.video.toJSON()
216 217
217 const wasPrivateVideo = options.video.privacy === VideoPrivacy.PRIVATE
218 const wasUnlistedVideo = options.video.privacy === VideoPrivacy.UNLISTED
219
220 // Check actor has the right to update the video 218 // Check actor has the right to update the video
221 const videoChannel = options.video.VideoChannel 219 const videoChannel = options.video.VideoChannel
222 if (videoChannel.Account.id !== options.account.id) { 220 if (videoChannel.Account.id !== options.account.id) {
@@ -281,15 +279,13 @@ async function updateVideoFromAP (options: {
281 }) 279 })
282 options.video.VideoCaptions = await Promise.all(videoCaptionsPromises) 280 options.video.VideoCaptions = await Promise.all(videoCaptionsPromises)
283 } 281 }
284
285 {
286 // Notify our users?
287 if (wasPrivateVideo || wasUnlistedVideo) {
288 Notifier.Instance.notifyOnNewVideo(options.video)
289 }
290 }
291 }) 282 })
292 283
284 // Notify our users?
285 if (wasPrivateVideo || wasUnlistedVideo) {
286 Notifier.Instance.notifyOnNewVideo(options.video)
287 }
288
293 logger.info('Remote video with uuid %s updated', options.videoObject.uuid) 289 logger.info('Remote video with uuid %s updated', options.videoObject.uuid)
294 } catch (err) { 290 } catch (err) {
295 if (options.video !== undefined && videoFieldsSave !== undefined) { 291 if (options.video !== undefined && videoFieldsSave !== undefined) {
diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts
index 959cc04fa..480d324dc 100644
--- a/server/lib/job-queue/handlers/video-file.ts
+++ b/server/lib/job-queue/handlers/video-file.ts
@@ -1,5 +1,5 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { VideoResolution, VideoState, Job } from '../../../../shared' 2import { VideoResolution, VideoState } from '../../../../shared'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { JobQueue } from '../job-queue' 5import { JobQueue } from '../job-queue'
@@ -8,7 +8,7 @@ import { retryTransactionWrapper } from '../../../helpers/database-utils'
8import { sequelizeTypescript } from '../../../initializers' 8import { sequelizeTypescript } from '../../../initializers'
9import * as Bluebird from 'bluebird' 9import * as Bluebird from 'bluebird'
10import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' 10import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils'
11import { importVideoFile, transcodeOriginalVideofile, optimizeVideofile } from '../../video-transcoding' 11import { importVideoFile, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding'
12import { Notifier } from '../../notifier' 12import { Notifier } from '../../notifier'
13 13
14export type VideoFilePayload = { 14export type VideoFilePayload = {
@@ -68,7 +68,7 @@ async function processVideoFile (job: Bull.Job) {
68async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { 68async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) {
69 if (video === undefined) return undefined 69 if (video === undefined) return undefined
70 70
71 return sequelizeTypescript.transaction(async t => { 71 const { videoDatabase, isNewVideo } = await sequelizeTypescript.transaction(async t => {
72 // Maybe the video changed in database, refresh it 72 // Maybe the video changed in database, refresh it
73 let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) 73 let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
74 // Video does not exist anymore 74 // Video does not exist anymore
@@ -87,10 +87,11 @@ async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) {
87 87
88 // If the video was not published, we consider it is a new one for other instances 88 // If the video was not published, we consider it is a new one for other instances
89 await federateVideoIfNeeded(videoDatabase, isNewVideo, t) 89 await federateVideoIfNeeded(videoDatabase, isNewVideo, t)
90 if (isNewVideo) Notifier.Instance.notifyOnNewVideo(video)
91 90
92 return undefined 91 return { videoDatabase, isNewVideo }
93 }) 92 })
93
94 if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase)
94} 95}
95 96
96async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) { 97async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) {
@@ -99,7 +100,7 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: bo
99 // Outside the transaction (IO on disk) 100 // Outside the transaction (IO on disk)
100 const { videoFileResolution } = await videoArg.getOriginalFileResolution() 101 const { videoFileResolution } = await videoArg.getOriginalFileResolution()
101 102
102 return sequelizeTypescript.transaction(async t => { 103 const videoDatabase = await sequelizeTypescript.transaction(async t => {
103 // Maybe the video changed in database, refresh it 104 // Maybe the video changed in database, refresh it
104 let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t) 105 let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t)
105 // Video does not exist anymore 106 // Video does not exist anymore
@@ -137,8 +138,11 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: bo
137 } 138 }
138 139
139 await federateVideoIfNeeded(videoDatabase, isNewVideo, t) 140 await federateVideoIfNeeded(videoDatabase, isNewVideo, t)
140 if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) 141
142 return videoDatabase
141 }) 143 })
144
145 if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase)
142} 146}
143 147
144// --------------------------------------------------------------------------- 148// ---------------------------------------------------------------------------
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 82edb8d5c..29cd1198c 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -180,12 +180,11 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
180 // Update video DB object 180 // Update video DB object
181 video.duration = duration 181 video.duration = duration
182 video.state = CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED 182 video.state = CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED
183 const videoUpdated = await video.save({ transaction: t }) 183 await video.save({ transaction: t })
184 184
185 // Now we can federate the video (reload from database, we need more attributes) 185 // Now we can federate the video (reload from database, we need more attributes)
186 const videoForFederation = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) 186 const videoForFederation = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
187 await federateVideoIfNeeded(videoForFederation, true, t) 187 await federateVideoIfNeeded(videoForFederation, true, t)
188 Notifier.Instance.notifyOnNewVideo(videoForFederation)
189 188
190 // Update video import object 189 // Update video import object
191 videoImport.state = VideoImportState.SUCCESS 190 videoImport.state = VideoImportState.SUCCESS
@@ -193,10 +192,12 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
193 192
194 logger.info('Video %s imported.', video.uuid) 193 logger.info('Video %s imported.', video.uuid)
195 194
196 videoImportUpdated.Video = videoUpdated 195 videoImportUpdated.Video = videoForFederation
197 return videoImportUpdated 196 return videoImportUpdated
198 }) 197 })
199 198
199 Notifier.Instance.notifyOnNewVideo(videoImportUpdated.Video)
200
200 // Create transcoding jobs? 201 // Create transcoding jobs?
201 if (videoImportUpdated.Video.state === VideoState.TO_TRANSCODE) { 202 if (videoImportUpdated.Video.state === VideoState.TO_TRANSCODE) {
202 // Put uuid because we don't have id auto incremented for now 203 // Put uuid because we don't have id auto incremented for now