diff options
Diffstat (limited to 'server/controllers/api/remote/videos.js')
-rw-r--r-- | server/controllers/api/remote/videos.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/server/controllers/api/remote/videos.js b/server/controllers/api/remote/videos.js index 39c9579c1..98891c99e 100644 --- a/server/controllers/api/remote/videos.js +++ b/server/controllers/api/remote/videos.js | |||
@@ -11,6 +11,7 @@ const secureMiddleware = middlewares.secure | |||
11 | const videosValidators = middlewares.validators.remote.videos | 11 | const videosValidators = middlewares.validators.remote.videos |
12 | const signatureValidators = middlewares.validators.remote.signature | 12 | const signatureValidators = middlewares.validators.remote.signature |
13 | const logger = require('../../../helpers/logger') | 13 | const logger = require('../../../helpers/logger') |
14 | const friends = require('../../../lib/friends') | ||
14 | const databaseUtils = require('../../../helpers/database-utils') | 15 | const databaseUtils = require('../../../helpers/database-utils') |
15 | 16 | ||
16 | const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] | 17 | const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] |
@@ -129,18 +130,22 @@ function processVideosEvents (eventData, fromPod, finalCallback) { | |||
129 | const options = { transaction: t } | 130 | const options = { transaction: t } |
130 | 131 | ||
131 | let columnToUpdate | 132 | let columnToUpdate |
133 | let qaduType | ||
132 | 134 | ||
133 | switch (eventData.eventType) { | 135 | switch (eventData.eventType) { |
134 | case constants.REQUEST_VIDEO_EVENT_TYPES.VIEWS: | 136 | case constants.REQUEST_VIDEO_EVENT_TYPES.VIEWS: |
135 | columnToUpdate = 'views' | 137 | columnToUpdate = 'views' |
138 | qaduType = constants.REQUEST_VIDEO_QADU_TYPES.VIEWS | ||
136 | break | 139 | break |
137 | 140 | ||
138 | case constants.REQUEST_VIDEO_EVENT_TYPES.LIKES: | 141 | case constants.REQUEST_VIDEO_EVENT_TYPES.LIKES: |
139 | columnToUpdate = 'likes' | 142 | columnToUpdate = 'likes' |
143 | qaduType = constants.REQUEST_VIDEO_QADU_TYPES.LIKES | ||
140 | break | 144 | break |
141 | 145 | ||
142 | case constants.REQUEST_VIDEO_EVENT_TYPES.DISLIKES: | 146 | case constants.REQUEST_VIDEO_EVENT_TYPES.DISLIKES: |
143 | columnToUpdate = 'dislikes' | 147 | columnToUpdate = 'dislikes' |
148 | qaduType = constants.REQUEST_VIDEO_QADU_TYPES.DISLIKES | ||
144 | break | 149 | break |
145 | 150 | ||
146 | default: | 151 | default: |
@@ -151,6 +156,19 @@ function processVideosEvents (eventData, fromPod, finalCallback) { | |||
151 | query[columnToUpdate] = eventData.count | 156 | query[columnToUpdate] = eventData.count |
152 | 157 | ||
153 | videoInstance.increment(query, options).asCallback(function (err) { | 158 | videoInstance.increment(query, options).asCallback(function (err) { |
159 | return callback(err, t, videoInstance, qaduType) | ||
160 | }) | ||
161 | }, | ||
162 | |||
163 | function sendQaduToFriends (t, videoInstance, qaduType, callback) { | ||
164 | const qadusParams = [ | ||
165 | { | ||
166 | videoId: videoInstance.id, | ||
167 | type: qaduType | ||
168 | } | ||
169 | ] | ||
170 | |||
171 | friends.quickAndDirtyUpdatesVideoToFriends(qadusParams, t, function (err) { | ||
154 | return callback(err, t) | 172 | return callback(err, t) |
155 | }) | 173 | }) |
156 | }, | 174 | }, |
@@ -159,7 +177,6 @@ function processVideosEvents (eventData, fromPod, finalCallback) { | |||
159 | 177 | ||
160 | ], function (err, t) { | 178 | ], function (err, t) { |
161 | if (err) { | 179 | if (err) { |
162 | console.log(err) | ||
163 | logger.debug('Cannot process a video event.', { error: err }) | 180 | logger.debug('Cannot process a video event.', { error: err }) |
164 | return databaseUtils.rollbackTransaction(err, t, finalCallback) | 181 | return databaseUtils.rollbackTransaction(err, t, finalCallback) |
165 | } | 182 | } |
@@ -278,7 +295,10 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) { | |||
278 | duration: videoToCreateData.duration, | 295 | duration: videoToCreateData.duration, |
279 | createdAt: videoToCreateData.createdAt, | 296 | createdAt: videoToCreateData.createdAt, |
280 | // FIXME: updatedAt does not seems to be considered by Sequelize | 297 | // FIXME: updatedAt does not seems to be considered by Sequelize |
281 | updatedAt: videoToCreateData.updatedAt | 298 | updatedAt: videoToCreateData.updatedAt, |
299 | views: videoToCreateData.views, | ||
300 | likes: videoToCreateData.likes, | ||
301 | dislikes: videoToCreateData.dislikes | ||
282 | } | 302 | } |
283 | 303 | ||
284 | const video = db.Video.build(videoData) | 304 | const video = db.Video.build(videoData) |
@@ -372,6 +392,9 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) { | |||
372 | videoInstance.set('createdAt', videoAttributesToUpdate.createdAt) | 392 | videoInstance.set('createdAt', videoAttributesToUpdate.createdAt) |
373 | videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt) | 393 | videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt) |
374 | videoInstance.set('extname', videoAttributesToUpdate.extname) | 394 | videoInstance.set('extname', videoAttributesToUpdate.extname) |
395 | videoInstance.set('views', videoAttributesToUpdate.views) | ||
396 | videoInstance.set('likes', videoAttributesToUpdate.likes) | ||
397 | videoInstance.set('dislikes', videoAttributesToUpdate.dislikes) | ||
375 | 398 | ||
376 | videoInstance.save(options).asCallback(function (err) { | 399 | videoInstance.save(options).asCallback(function (err) { |
377 | return callback(err, t, videoInstance, tagInstances) | 400 | return callback(err, t, videoInstance, tagInstances) |