diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 11:26:35 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 11:26:35 +0200 |
commit | a041b1714715593b46805d7fd0106501770d11c3 (patch) | |
tree | 952a2fb70839c82a084252a4746ba62a0ef2e8ea /server/controllers/api | |
parent | 51c443dbe0284c5ec54033be06f554ec37397bce (diff) | |
download | PeerTube-a041b1714715593b46805d7fd0106501770d11c3.tar.gz PeerTube-a041b1714715593b46805d7fd0106501770d11c3.tar.zst PeerTube-a041b1714715593b46805d7fd0106501770d11c3.zip |
Reset video fields when remote update fails
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/remote/videos.ts | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index bf442c6e5..d0febdd4b 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts | |||
@@ -16,7 +16,7 @@ import { | |||
16 | remoteQaduVideosValidator, | 16 | remoteQaduVideosValidator, |
17 | remoteEventsVideosValidator | 17 | remoteEventsVideosValidator |
18 | } from '../../../middlewares' | 18 | } from '../../../middlewares' |
19 | import { logger, retryTransactionWrapper } from '../../../helpers' | 19 | import { logger, retryTransactionWrapper, resetSequelizeInstance } from '../../../helpers' |
20 | import { quickAndDirtyUpdatesVideoToFriends, fetchVideoChannelByHostAndUUID } from '../../../lib' | 20 | import { quickAndDirtyUpdatesVideoToFriends, fetchVideoChannelByHostAndUUID } from '../../../lib' |
21 | import { PodInstance, VideoFileInstance } from '../../../models' | 21 | import { PodInstance, VideoFileInstance } from '../../../models' |
22 | import { | 22 | import { |
@@ -35,6 +35,7 @@ import { | |||
35 | RemoteVideoAuthorRemoveData, | 35 | RemoteVideoAuthorRemoveData, |
36 | RemoteVideoAuthorCreateData | 36 | RemoteVideoAuthorCreateData |
37 | } from '../../../../shared' | 37 | } from '../../../../shared' |
38 | import { VideoInstance } from '../../../models/video/video-interface' | ||
38 | 39 | ||
39 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] | 40 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] |
40 | 41 | ||
@@ -145,7 +146,7 @@ async function processVideosEventsRetryWrapper (eventData: RemoteVideoEventData, | |||
145 | async function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) { | 146 | async function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) { |
146 | await db.sequelize.transaction(async t => { | 147 | await db.sequelize.transaction(async t => { |
147 | const sequelizeOptions = { transaction: t } | 148 | const sequelizeOptions = { transaction: t } |
148 | const videoInstance = await fetchVideoByUUID(eventData.uuid, t) | 149 | const videoInstance = await fetchLocalVideoByUUID(eventData.uuid, t) |
149 | 150 | ||
150 | let columnToUpdate | 151 | let columnToUpdate |
151 | let qaduType | 152 | let qaduType |
@@ -306,6 +307,8 @@ async function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: RemoteVid | |||
306 | 307 | ||
307 | async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) { | 308 | async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) { |
308 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) | 309 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) |
310 | let videoInstance: VideoInstance | ||
311 | let videoFieldsSave: object | ||
309 | 312 | ||
310 | try { | 313 | try { |
311 | await db.sequelize.transaction(async t => { | 314 | await db.sequelize.transaction(async t => { |
@@ -314,6 +317,7 @@ async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData | |||
314 | } | 317 | } |
315 | 318 | ||
316 | const videoInstance = await fetchVideoByHostAndUUID(fromPod.host, videoAttributesToUpdate.uuid, t) | 319 | const videoInstance = await fetchVideoByHostAndUUID(fromPod.host, videoAttributesToUpdate.uuid, t) |
320 | videoFieldsSave = videoInstance.toJSON() | ||
317 | const tags = videoAttributesToUpdate.tags | 321 | const tags = videoAttributesToUpdate.tags |
318 | 322 | ||
319 | const tagInstances = await db.Tag.findOrCreateTags(tags, t) | 323 | const tagInstances = await db.Tag.findOrCreateTags(tags, t) |
@@ -360,6 +364,10 @@ async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData | |||
360 | 364 | ||
361 | logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid) | 365 | logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid) |
362 | } catch (err) { | 366 | } catch (err) { |
367 | if (videoInstance !== undefined && videoFieldsSave !== undefined) { | ||
368 | resetSequelizeInstance(videoInstance, videoFieldsSave) | ||
369 | } | ||
370 | |||
363 | // This is just a debug because we will retry the insert | 371 | // This is just a debug because we will retry the insert |
364 | logger.debug('Cannot update the remote video.', err) | 372 | logger.debug('Cannot update the remote video.', err) |
365 | throw err | 373 | throw err |
@@ -538,7 +546,7 @@ async function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, f | |||
538 | logger.debug('Reporting remote abuse for video %s.', reportData.videoUUID) | 546 | logger.debug('Reporting remote abuse for video %s.', reportData.videoUUID) |
539 | 547 | ||
540 | await db.sequelize.transaction(async t => { | 548 | await db.sequelize.transaction(async t => { |
541 | const videoInstance = await fetchVideoByUUID(reportData.videoUUID, t) | 549 | const videoInstance = await fetchLocalVideoByUUID(reportData.videoUUID, t) |
542 | const videoAbuseData = { | 550 | const videoAbuseData = { |
543 | reporterUsername: reportData.reporterUsername, | 551 | reporterUsername: reportData.reporterUsername, |
544 | reason: reportData.reportReason, | 552 | reason: reportData.reportReason, |
@@ -553,9 +561,9 @@ async function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, f | |||
553 | logger.info('Remote abuse for video uuid %s created', reportData.videoUUID) | 561 | logger.info('Remote abuse for video uuid %s created', reportData.videoUUID) |
554 | } | 562 | } |
555 | 563 | ||
556 | async function fetchVideoByUUID (id: string, t: Sequelize.Transaction) { | 564 | async function fetchLocalVideoByUUID (id: string, t: Sequelize.Transaction) { |
557 | try { | 565 | try { |
558 | const video = await db.Video.loadByUUID(id, t) | 566 | const video = await db.Video.loadLocalVideoByUUID(id, t) |
559 | 567 | ||
560 | if (!video) throw new Error('Video ' + id + ' not found') | 568 | if (!video) throw new Error('Video ' + id + ' not found') |
561 | 569 | ||