const videosValidators = middlewares.validators.remote.videos
const signatureValidators = middlewares.validators.remote.signature
const logger = require('../../../helpers/logger')
+const friends = require('../../../lib/friends')
const databaseUtils = require('../../../helpers/database-utils')
const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
const options = { transaction: t }
let columnToUpdate
+ let qaduType
switch (eventData.eventType) {
case constants.REQUEST_VIDEO_EVENT_TYPES.VIEWS:
columnToUpdate = 'views'
+ qaduType = constants.REQUEST_VIDEO_QADU_TYPES.VIEWS
break
case constants.REQUEST_VIDEO_EVENT_TYPES.LIKES:
columnToUpdate = 'likes'
+ qaduType = constants.REQUEST_VIDEO_QADU_TYPES.LIKES
break
case constants.REQUEST_VIDEO_EVENT_TYPES.DISLIKES:
columnToUpdate = 'dislikes'
+ qaduType = constants.REQUEST_VIDEO_QADU_TYPES.DISLIKES
break
default:
query[columnToUpdate] = eventData.count
videoInstance.increment(query, options).asCallback(function (err) {
+ return callback(err, t, videoInstance, qaduType)
+ })
+ },
+
+ function sendQaduToFriends (t, videoInstance, qaduType, callback) {
+ const qadusParams = [
+ {
+ videoId: videoInstance.id,
+ type: qaduType
+ }
+ ]
+
+ friends.quickAndDirtyUpdatesVideoToFriends(qadusParams, t, function (err) {
return callback(err, t)
})
},
], function (err, t) {
if (err) {
- console.log(err)
logger.debug('Cannot process a video event.', { error: err })
return databaseUtils.rollbackTransaction(err, t, finalCallback)
}
}
function quickAndDirtyUpdateVideo (videoData, fromPod, finalCallback) {
+ let videoName
+
waterfall([
databaseUtils.startSerializableTransaction,
function updateVideoIntoDB (t, videoInstance, callback) {
const options = { transaction: t }
+ videoName = videoInstance.name
+
if (videoData.views) {
videoInstance.set('views', videoData.views)
}
return databaseUtils.rollbackTransaction(err, t, finalCallback)
}
- logger.info('Remote video %s quick and dirty updated', videoData.name)
+ logger.info('Remote video %s quick and dirty updated', videoName)
return finalCallback(null)
})
}
remoteId: videoToCreateData.remoteId,
extname: videoToCreateData.extname,
infoHash: videoToCreateData.infoHash,
+ category: videoToCreateData.category,
+ licence: videoToCreateData.licence,
description: videoToCreateData.description,
authorId: author.id,
duration: videoToCreateData.duration,
createdAt: videoToCreateData.createdAt,
// FIXME: updatedAt does not seems to be considered by Sequelize
- updatedAt: videoToCreateData.updatedAt
+ updatedAt: videoToCreateData.updatedAt,
+ views: videoToCreateData.views,
+ likes: videoToCreateData.likes,
+ dislikes: videoToCreateData.dislikes
}
const video = db.Video.build(videoData)
const options = { transaction: t }
videoInstance.set('name', videoAttributesToUpdate.name)
+ videoInstance.set('category', videoAttributesToUpdate.category)
+ videoInstance.set('licence', videoAttributesToUpdate.licence)
videoInstance.set('description', videoAttributesToUpdate.description)
videoInstance.set('infoHash', videoAttributesToUpdate.infoHash)
videoInstance.set('duration', videoAttributesToUpdate.duration)
videoInstance.set('createdAt', videoAttributesToUpdate.createdAt)
videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt)
videoInstance.set('extname', videoAttributesToUpdate.extname)
+ videoInstance.set('views', videoAttributesToUpdate.views)
+ videoInstance.set('likes', videoAttributesToUpdate.likes)
+ videoInstance.set('dislikes', videoAttributesToUpdate.dislikes)
videoInstance.save(options).asCallback(function (err) {
return callback(err, t, videoInstance, tagInstances)