+
+ ], function andFinally (err, t) {
+ if (err) {
+ logger.debug('Cannot update the video.', { error: err })
+
+ // Abort transaction?
+ if (t) t.rollback()
+
+ // Force fields we want to update
+ // If the transaction is retried, sequelize will think the object has not changed
+ // So it will skip the SQL request, even if the last one was ROLLBACKed!
+ Object.keys(videoFieldsSave).forEach(function (key) {
+ const value = videoFieldsSave[key]
+ videoInstance.set(key, value)
+ })
+
+ return finalCallback(err)
+ }
+
+ // Commit transaction
+ t.commit().asCallback(function (err) {
+ if (err) return finalCallback(err)
+
+ logger.info('Video with name %s updated.', videoInfosToUpdate.name)
+ return finalCallback(null)
+ })
+ })
+}
+
+function getVideo (req, res, next) {
+ const videoInstance = res.locals.video
+ res.json(videoInstance.toFormatedJSON())
+}
+
+function listVideos (req, res, next) {
+ db.Video.listForApi(req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) {
+ if (err) return next(err)
+
+ res.json(utils.getFormatedObjects(videosList, videosTotal))
+ })
+}
+
+function removeVideo (req, res, next) {
+ const videoInstance = res.locals.video
+
+ videoInstance.destroy().asCallback(function (err) {