aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-26 11:26:35 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 11:26:35 +0200
commita041b1714715593b46805d7fd0106501770d11c3 (patch)
tree952a2fb70839c82a084252a4746ba62a0ef2e8ea
parent51c443dbe0284c5ec54033be06f554ec37397bce (diff)
downloadPeerTube-a041b1714715593b46805d7fd0106501770d11c3.tar.gz
PeerTube-a041b1714715593b46805d7fd0106501770d11c3.tar.zst
PeerTube-a041b1714715593b46805d7fd0106501770d11c3.zip
Reset video fields when remote update fails
-rw-r--r--server/controllers/api/remote/videos.ts18
-rw-r--r--server/models/video/video-interface.ts2
-rw-r--r--server/models/video/video.ts16
3 files changed, 31 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'
19import { logger, retryTransactionWrapper } from '../../../helpers' 19import { logger, retryTransactionWrapper, resetSequelizeInstance } from '../../../helpers'
20import { quickAndDirtyUpdatesVideoToFriends, fetchVideoChannelByHostAndUUID } from '../../../lib' 20import { quickAndDirtyUpdatesVideoToFriends, fetchVideoChannelByHostAndUUID } from '../../../lib'
21import { PodInstance, VideoFileInstance } from '../../../models' 21import { PodInstance, VideoFileInstance } from '../../../models'
22import { 22import {
@@ -35,6 +35,7 @@ import {
35 RemoteVideoAuthorRemoveData, 35 RemoteVideoAuthorRemoveData,
36 RemoteVideoAuthorCreateData 36 RemoteVideoAuthorCreateData
37} from '../../../../shared' 37} from '../../../../shared'
38import { VideoInstance } from '../../../models/video/video-interface'
38 39
39const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] 40const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
40 41
@@ -145,7 +146,7 @@ async function processVideosEventsRetryWrapper (eventData: RemoteVideoEventData,
145async function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) { 146async 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
307async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) { 308async 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
556async function fetchVideoByUUID (id: string, t: Sequelize.Transaction) { 564async 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
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts
index dd457bb00..2afbaf09e 100644
--- a/server/models/video/video-interface.ts
+++ b/server/models/video/video-interface.ts
@@ -57,6 +57,7 @@ export namespace VideoMethods {
57 57
58 export type Load = (id: number) => Promise<VideoInstance> 58 export type Load = (id: number) => Promise<VideoInstance>
59 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance> 59 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
60 export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
60 export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance> 61 export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
61 export type LoadAndPopulateAuthor = (id: number) => Promise<VideoInstance> 62 export type LoadAndPopulateAuthor = (id: number) => Promise<VideoInstance>
62 export type LoadAndPopulateAuthorAndPodAndTags = (id: number) => Promise<VideoInstance> 63 export type LoadAndPopulateAuthorAndPodAndTags = (id: number) => Promise<VideoInstance>
@@ -79,6 +80,7 @@ export interface VideoClass {
79 loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags 80 loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
80 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID 81 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
81 loadByUUID: VideoMethods.LoadByUUID 82 loadByUUID: VideoMethods.LoadByUUID
83 loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
82 loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags 84 loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
83 searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags 85 searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags
84} 86}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index d9b976404..01a801da3 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -80,6 +80,7 @@ let listOwnedAndPopulateAuthorAndTags: VideoMethods.ListOwnedAndPopulateAuthorAn
80let listOwnedByAuthor: VideoMethods.ListOwnedByAuthor 80let listOwnedByAuthor: VideoMethods.ListOwnedByAuthor
81let load: VideoMethods.Load 81let load: VideoMethods.Load
82let loadByUUID: VideoMethods.LoadByUUID 82let loadByUUID: VideoMethods.LoadByUUID
83let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
83let loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor 84let loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor
84let loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags 85let loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
85let loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags 86let loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
@@ -247,6 +248,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
247 loadAndPopulateAuthorAndPodAndTags, 248 loadAndPopulateAuthorAndPodAndTags,
248 loadByHostAndUUID, 249 loadByHostAndUUID,
249 loadByUUID, 250 loadByUUID,
251 loadLocalVideoByUUID,
250 loadByUUIDAndPopulateAuthorAndPodAndTags, 252 loadByUUIDAndPopulateAuthorAndPodAndTags,
251 searchAndPopulateAuthorAndPodAndTags 253 searchAndPopulateAuthorAndPodAndTags
252 ] 254 ]
@@ -899,6 +901,20 @@ loadByUUID = function (uuid: string, t?: Sequelize.Transaction) {
899 return Video.findOne(query) 901 return Video.findOne(query)
900} 902}
901 903
904loadLocalVideoByUUID = function (uuid: string, t?: Sequelize.Transaction) {
905 const query: Sequelize.FindOptions<VideoAttributes> = {
906 where: {
907 uuid,
908 remote: false
909 },
910 include: [ Video['sequelize'].models.VideoFile ]
911 }
912
913 if (t !== undefined) query.transaction = t
914
915 return Video.findOne(query)
916}
917
902loadAndPopulateAuthor = function (id: number) { 918loadAndPopulateAuthor = function (id: number) {
903 const options = { 919 const options = {
904 include: [ 920 include: [