Reset video fields when remote update fails
This commit is contained in:
parent
51c443dbe0
commit
a041b17147
|
@ -16,7 +16,7 @@ import {
|
||||||
remoteQaduVideosValidator,
|
remoteQaduVideosValidator,
|
||||||
remoteEventsVideosValidator
|
remoteEventsVideosValidator
|
||||||
} from '../../../middlewares'
|
} from '../../../middlewares'
|
||||||
import { logger, retryTransactionWrapper } from '../../../helpers'
|
import { logger, retryTransactionWrapper, resetSequelizeInstance } from '../../../helpers'
|
||||||
import { quickAndDirtyUpdatesVideoToFriends, fetchVideoChannelByHostAndUUID } from '../../../lib'
|
import { quickAndDirtyUpdatesVideoToFriends, fetchVideoChannelByHostAndUUID } from '../../../lib'
|
||||||
import { PodInstance, VideoFileInstance } from '../../../models'
|
import { PodInstance, VideoFileInstance } from '../../../models'
|
||||||
import {
|
import {
|
||||||
|
@ -35,6 +35,7 @@ import {
|
||||||
RemoteVideoAuthorRemoveData,
|
RemoteVideoAuthorRemoveData,
|
||||||
RemoteVideoAuthorCreateData
|
RemoteVideoAuthorCreateData
|
||||||
} from '../../../../shared'
|
} from '../../../../shared'
|
||||||
|
import { VideoInstance } from '../../../models/video/video-interface'
|
||||||
|
|
||||||
const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
|
const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ async function processVideosEventsRetryWrapper (eventData: RemoteVideoEventData,
|
||||||
async function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) {
|
async function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) {
|
||||||
await db.sequelize.transaction(async t => {
|
await db.sequelize.transaction(async t => {
|
||||||
const sequelizeOptions = { transaction: t }
|
const sequelizeOptions = { transaction: t }
|
||||||
const videoInstance = await fetchVideoByUUID(eventData.uuid, t)
|
const videoInstance = await fetchLocalVideoByUUID(eventData.uuid, t)
|
||||||
|
|
||||||
let columnToUpdate
|
let columnToUpdate
|
||||||
let qaduType
|
let qaduType
|
||||||
|
@ -306,6 +307,8 @@ async function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: RemoteVid
|
||||||
|
|
||||||
async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) {
|
async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) {
|
||||||
logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid)
|
logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid)
|
||||||
|
let videoInstance: VideoInstance
|
||||||
|
let videoFieldsSave: object
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await db.sequelize.transaction(async t => {
|
await db.sequelize.transaction(async t => {
|
||||||
|
@ -314,6 +317,7 @@ async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoInstance = await fetchVideoByHostAndUUID(fromPod.host, videoAttributesToUpdate.uuid, t)
|
const videoInstance = await fetchVideoByHostAndUUID(fromPod.host, videoAttributesToUpdate.uuid, t)
|
||||||
|
videoFieldsSave = videoInstance.toJSON()
|
||||||
const tags = videoAttributesToUpdate.tags
|
const tags = videoAttributesToUpdate.tags
|
||||||
|
|
||||||
const tagInstances = await db.Tag.findOrCreateTags(tags, t)
|
const tagInstances = await db.Tag.findOrCreateTags(tags, t)
|
||||||
|
@ -360,6 +364,10 @@ async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData
|
||||||
|
|
||||||
logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid)
|
logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (videoInstance !== undefined && videoFieldsSave !== undefined) {
|
||||||
|
resetSequelizeInstance(videoInstance, videoFieldsSave)
|
||||||
|
}
|
||||||
|
|
||||||
// This is just a debug because we will retry the insert
|
// This is just a debug because we will retry the insert
|
||||||
logger.debug('Cannot update the remote video.', err)
|
logger.debug('Cannot update the remote video.', err)
|
||||||
throw err
|
throw err
|
||||||
|
@ -538,7 +546,7 @@ async function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, f
|
||||||
logger.debug('Reporting remote abuse for video %s.', reportData.videoUUID)
|
logger.debug('Reporting remote abuse for video %s.', reportData.videoUUID)
|
||||||
|
|
||||||
await db.sequelize.transaction(async t => {
|
await db.sequelize.transaction(async t => {
|
||||||
const videoInstance = await fetchVideoByUUID(reportData.videoUUID, t)
|
const videoInstance = await fetchLocalVideoByUUID(reportData.videoUUID, t)
|
||||||
const videoAbuseData = {
|
const videoAbuseData = {
|
||||||
reporterUsername: reportData.reporterUsername,
|
reporterUsername: reportData.reporterUsername,
|
||||||
reason: reportData.reportReason,
|
reason: reportData.reportReason,
|
||||||
|
@ -553,9 +561,9 @@ async function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, f
|
||||||
logger.info('Remote abuse for video uuid %s created', reportData.videoUUID)
|
logger.info('Remote abuse for video uuid %s created', reportData.videoUUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchVideoByUUID (id: string, t: Sequelize.Transaction) {
|
async function fetchLocalVideoByUUID (id: string, t: Sequelize.Transaction) {
|
||||||
try {
|
try {
|
||||||
const video = await db.Video.loadByUUID(id, t)
|
const video = await db.Video.loadLocalVideoByUUID(id, t)
|
||||||
|
|
||||||
if (!video) throw new Error('Video ' + id + ' not found')
|
if (!video) throw new Error('Video ' + id + ' not found')
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ export namespace VideoMethods {
|
||||||
|
|
||||||
export type Load = (id: number) => Promise<VideoInstance>
|
export type Load = (id: number) => Promise<VideoInstance>
|
||||||
export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
|
export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
|
||||||
|
export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
|
||||||
export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
|
export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Promise<VideoInstance>
|
||||||
export type LoadAndPopulateAuthor = (id: number) => Promise<VideoInstance>
|
export type LoadAndPopulateAuthor = (id: number) => Promise<VideoInstance>
|
||||||
export type LoadAndPopulateAuthorAndPodAndTags = (id: number) => Promise<VideoInstance>
|
export type LoadAndPopulateAuthorAndPodAndTags = (id: number) => Promise<VideoInstance>
|
||||||
|
@ -79,6 +80,7 @@ export interface VideoClass {
|
||||||
loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
|
loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
|
||||||
loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
|
loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
|
||||||
loadByUUID: VideoMethods.LoadByUUID
|
loadByUUID: VideoMethods.LoadByUUID
|
||||||
|
loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
|
||||||
loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
|
loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
|
||||||
searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags
|
searchAndPopulateAuthorAndPodAndTags: VideoMethods.SearchAndPopulateAuthorAndPodAndTags
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,7 @@ let listOwnedAndPopulateAuthorAndTags: VideoMethods.ListOwnedAndPopulateAuthorAn
|
||||||
let listOwnedByAuthor: VideoMethods.ListOwnedByAuthor
|
let listOwnedByAuthor: VideoMethods.ListOwnedByAuthor
|
||||||
let load: VideoMethods.Load
|
let load: VideoMethods.Load
|
||||||
let loadByUUID: VideoMethods.LoadByUUID
|
let loadByUUID: VideoMethods.LoadByUUID
|
||||||
|
let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
|
||||||
let loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor
|
let loadAndPopulateAuthor: VideoMethods.LoadAndPopulateAuthor
|
||||||
let loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
|
let loadAndPopulateAuthorAndPodAndTags: VideoMethods.LoadAndPopulateAuthorAndPodAndTags
|
||||||
let loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
|
let loadByUUIDAndPopulateAuthorAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAuthorAndPodAndTags
|
||||||
|
@ -247,6 +248,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
|
||||||
loadAndPopulateAuthorAndPodAndTags,
|
loadAndPopulateAuthorAndPodAndTags,
|
||||||
loadByHostAndUUID,
|
loadByHostAndUUID,
|
||||||
loadByUUID,
|
loadByUUID,
|
||||||
|
loadLocalVideoByUUID,
|
||||||
loadByUUIDAndPopulateAuthorAndPodAndTags,
|
loadByUUIDAndPopulateAuthorAndPodAndTags,
|
||||||
searchAndPopulateAuthorAndPodAndTags
|
searchAndPopulateAuthorAndPodAndTags
|
||||||
]
|
]
|
||||||
|
@ -899,6 +901,20 @@ loadByUUID = function (uuid: string, t?: Sequelize.Transaction) {
|
||||||
return Video.findOne(query)
|
return Video.findOne(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadLocalVideoByUUID = function (uuid: string, t?: Sequelize.Transaction) {
|
||||||
|
const query: Sequelize.FindOptions<VideoAttributes> = {
|
||||||
|
where: {
|
||||||
|
uuid,
|
||||||
|
remote: false
|
||||||
|
},
|
||||||
|
include: [ Video['sequelize'].models.VideoFile ]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t !== undefined) query.transaction = t
|
||||||
|
|
||||||
|
return Video.findOne(query)
|
||||||
|
}
|
||||||
|
|
||||||
loadAndPopulateAuthor = function (id: number) {
|
loadAndPopulateAuthor = function (id: number) {
|
||||||
const options = {
|
const options = {
|
||||||
include: [
|
include: [
|
||||||
|
|
Loading…
Reference in New Issue