diff options
Diffstat (limited to 'server/controllers/api/remote/videos.ts')
-rw-r--r-- | server/controllers/api/remote/videos.ts | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index 9dd4afdb5..23023211f 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts | |||
@@ -17,7 +17,7 @@ import { | |||
17 | } from '../../../middlewares' | 17 | } from '../../../middlewares' |
18 | import { logger, retryTransactionWrapper } from '../../../helpers' | 18 | import { logger, retryTransactionWrapper } from '../../../helpers' |
19 | import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' | 19 | import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' |
20 | import { PodInstance } from '../../../models' | 20 | import { PodInstance, VideoFileInstance } from '../../../models' |
21 | import { | 21 | import { |
22 | RemoteVideoRequest, | 22 | RemoteVideoRequest, |
23 | RemoteVideoCreateData, | 23 | RemoteVideoCreateData, |
@@ -81,7 +81,7 @@ function remoteVideos (req: express.Request, res: express.Response, next: expres | |||
81 | // Get the function we need to call in order to process the request | 81 | // Get the function we need to call in order to process the request |
82 | const fun = functionsHash[request.type] | 82 | const fun = functionsHash[request.type] |
83 | if (fun === undefined) { | 83 | if (fun === undefined) { |
84 | logger.error('Unkown remote request type %s.', request.type) | 84 | logger.error('Unknown remote request type %s.', request.type) |
85 | return | 85 | return |
86 | } | 86 | } |
87 | 87 | ||
@@ -176,7 +176,7 @@ function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInsta | |||
176 | return quickAndDirtyUpdatesVideoToFriends(qadusParams, t) | 176 | return quickAndDirtyUpdatesVideoToFriends(qadusParams, t) |
177 | }) | 177 | }) |
178 | }) | 178 | }) |
179 | .then(() => logger.info('Remote video event processed for video %s.', eventData.uuid)) | 179 | .then(() => logger.info('Remote video event processed for video with uuid %s.', eventData.uuid)) |
180 | .catch(err => { | 180 | .catch(err => { |
181 | logger.debug('Cannot process a video event.', err) | 181 | logger.debug('Cannot process a video event.', err) |
182 | throw err | 182 | throw err |
@@ -193,14 +193,14 @@ function quickAndDirtyUpdateVideoRetryWrapper (videoData: RemoteQaduVideoData, f | |||
193 | } | 193 | } |
194 | 194 | ||
195 | function quickAndDirtyUpdateVideo (videoData: RemoteQaduVideoData, fromPod: PodInstance) { | 195 | function quickAndDirtyUpdateVideo (videoData: RemoteQaduVideoData, fromPod: PodInstance) { |
196 | let videoName | 196 | let videoUUID = '' |
197 | 197 | ||
198 | return db.sequelize.transaction(t => { | 198 | return db.sequelize.transaction(t => { |
199 | return fetchVideoByHostAndUUID(fromPod.host, videoData.uuid) | 199 | return fetchVideoByHostAndUUID(fromPod.host, videoData.uuid) |
200 | .then(videoInstance => { | 200 | .then(videoInstance => { |
201 | const options = { transaction: t } | 201 | const options = { transaction: t } |
202 | 202 | ||
203 | videoName = videoInstance.name | 203 | videoUUID = videoInstance.uuid |
204 | 204 | ||
205 | if (videoData.views) { | 205 | if (videoData.views) { |
206 | videoInstance.set('views', videoData.views) | 206 | videoInstance.set('views', videoData.views) |
@@ -217,7 +217,7 @@ function quickAndDirtyUpdateVideo (videoData: RemoteQaduVideoData, fromPod: PodI | |||
217 | return videoInstance.save(options) | 217 | return videoInstance.save(options) |
218 | }) | 218 | }) |
219 | }) | 219 | }) |
220 | .then(() => logger.info('Remote video %s quick and dirty updated', videoName)) | 220 | .then(() => logger.info('Remote video with uuid %s quick and dirty updated', videoUUID)) |
221 | .catch(err => logger.debug('Cannot quick and dirty update the remote video.', err)) | 221 | .catch(err => logger.debug('Cannot quick and dirty update the remote video.', err)) |
222 | } | 222 | } |
223 | 223 | ||
@@ -315,7 +315,7 @@ function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodI | |||
315 | return videoCreated.setTags(tagInstances, options) | 315 | return videoCreated.setTags(tagInstances, options) |
316 | }) | 316 | }) |
317 | }) | 317 | }) |
318 | .then(() => logger.info('Remote video %s inserted.', videoToCreateData.name)) | 318 | .then(() => logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid)) |
319 | .catch(err => { | 319 | .catch(err => { |
320 | logger.debug('Cannot insert the remote video.', err) | 320 | logger.debug('Cannot insert the remote video.', err) |
321 | throw err | 321 | throw err |
@@ -361,7 +361,17 @@ function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, from | |||
361 | return videoInstance.save(options).then(() => ({ videoInstance, tagInstances })) | 361 | return videoInstance.save(options).then(() => ({ videoInstance, tagInstances })) |
362 | }) | 362 | }) |
363 | .then(({ tagInstances, videoInstance }) => { | 363 | .then(({ tagInstances, videoInstance }) => { |
364 | const tasks = [] | 364 | const tasks: Promise<void>[] = [] |
365 | |||
366 | // Remove old video files | ||
367 | videoInstance.VideoFiles.forEach(videoFile => { | ||
368 | tasks.push(videoFile.destroy()) | ||
369 | }) | ||
370 | |||
371 | return Promise.all(tasks).then(() => ({ tagInstances, videoInstance })) | ||
372 | }) | ||
373 | .then(({ tagInstances, videoInstance }) => { | ||
374 | const tasks: Promise<VideoFileInstance>[] = [] | ||
365 | const options = { | 375 | const options = { |
366 | transaction: t | 376 | transaction: t |
367 | } | 377 | } |
@@ -386,7 +396,7 @@ function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, from | |||
386 | return videoInstance.setTags(tagInstances, options) | 396 | return videoInstance.setTags(tagInstances, options) |
387 | }) | 397 | }) |
388 | }) | 398 | }) |
389 | .then(() => logger.info('Remote video %s updated', videoAttributesToUpdate.name)) | 399 | .then(() => logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid)) |
390 | .catch(err => { | 400 | .catch(err => { |
391 | // This is just a debug because we will retry the insert | 401 | // This is just a debug because we will retry the insert |
392 | logger.debug('Cannot update the remote video.', err) | 402 | logger.debug('Cannot update the remote video.', err) |
@@ -398,7 +408,7 @@ function removeRemoteVideo (videoToRemoveData: RemoteVideoRemoveData, fromPod: P | |||
398 | // We need the instance because we have to remove some other stuffs (thumbnail etc) | 408 | // We need the instance because we have to remove some other stuffs (thumbnail etc) |
399 | return fetchVideoByHostAndUUID(fromPod.host, videoToRemoveData.uuid) | 409 | return fetchVideoByHostAndUUID(fromPod.host, videoToRemoveData.uuid) |
400 | .then(video => { | 410 | .then(video => { |
401 | logger.debug('Removing remote video %s.', video.uuid) | 411 | logger.debug('Removing remote video with uuid %s.', video.uuid) |
402 | return video.destroy() | 412 | return video.destroy() |
403 | }) | 413 | }) |
404 | .catch(err => { | 414 | .catch(err => { |