remoteQaduVideosValidator,
remoteEventsVideosValidator
} from '../../../middlewares'
-import { logger, retryTransactionWrapper } from '../../../helpers'
+import { logger, retryTransactionWrapper, resetSequelizeInstance } from '../../../helpers'
import { quickAndDirtyUpdatesVideoToFriends, fetchVideoChannelByHostAndUUID } from '../../../lib'
import { PodInstance, VideoFileInstance } from '../../../models'
import {
RemoteVideoAuthorRemoveData,
RemoteVideoAuthorCreateData
} from '../../../../shared'
+import { VideoInstance } from '../../../models/video/video-interface'
const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
async function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) {
await db.sequelize.transaction(async t => {
const sequelizeOptions = { transaction: t }
- const videoInstance = await fetchVideoByUUID(eventData.uuid, t)
+ const videoInstance = await fetchLocalVideoByUUID(eventData.uuid, t)
let columnToUpdate
let qaduType
licence: videoToCreateData.licence,
language: videoToCreateData.language,
nsfw: videoToCreateData.nsfw,
- description: videoToCreateData.description,
+ description: videoToCreateData.truncatedDescription,
channelId: videoChannel.id,
duration: videoToCreateData.duration,
createdAt: videoToCreateData.createdAt,
async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) {
logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid)
+ let videoInstance: VideoInstance
+ let videoFieldsSave: object
try {
await db.sequelize.transaction(async t => {
}
const videoInstance = await fetchVideoByHostAndUUID(fromPod.host, videoAttributesToUpdate.uuid, t)
+ videoFieldsSave = videoInstance.toJSON()
const tags = videoAttributesToUpdate.tags
const tagInstances = await db.Tag.findOrCreateTags(tags, t)
videoInstance.set('licence', videoAttributesToUpdate.licence)
videoInstance.set('language', videoAttributesToUpdate.language)
videoInstance.set('nsfw', videoAttributesToUpdate.nsfw)
- videoInstance.set('description', videoAttributesToUpdate.description)
+ videoInstance.set('description', videoAttributesToUpdate.truncatedDescription)
videoInstance.set('duration', videoAttributesToUpdate.duration)
videoInstance.set('createdAt', videoAttributesToUpdate.createdAt)
videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt)
logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid)
} catch (err) {
+ if (videoInstance !== undefined && videoFieldsSave !== undefined) {
+ resetSequelizeInstance(videoInstance, videoFieldsSave)
+ }
+
// This is just a debug because we will retry the insert
logger.debug('Cannot update the remote video.', err)
throw err
logger.debug('Reporting remote abuse for video %s.', reportData.videoUUID)
await db.sequelize.transaction(async t => {
- const videoInstance = await fetchVideoByUUID(reportData.videoUUID, t)
+ const videoInstance = await fetchLocalVideoByUUID(reportData.videoUUID, t)
const videoAbuseData = {
reporterUsername: reportData.reporterUsername,
reason: reportData.reportReason,
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 {
- 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')