]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video.js
Server: transaction serializable for videos
[github/Chocobozzz/PeerTube.git] / server / models / video.js
index 14fbe2f719ab2ca79dafdf28b3d2235217ce52e7..b3060705d9cd981dfd6c4ecd4bf74caa77b6516a 100644 (file)
@@ -20,7 +20,6 @@ const customVideosValidators = require('../helpers/custom-validators').videos
 // ---------------------------------------------------------------------------
 
 module.exports = function (sequelize, DataTypes) {
-  // TODO: add indexes on searchable columns
   const Video = sequelize.define('Video',
     {
       id: {
@@ -111,10 +110,10 @@ module.exports = function (sequelize, DataTypes) {
         getDurationFromFile,
         list,
         listForApi,
-        listByHostAndRemoteId,
         listOwnedAndPopulateAuthorAndTags,
         listOwnedByAuthor,
         load,
+        loadByHostAndRemoteId,
         loadAndPopulateAuthor,
         loadAndPopulateAuthorAndPodAndTags,
         searchAndPopulateAuthorAndPodAndTags
@@ -219,7 +218,6 @@ function afterDestroy (video, options, next) {
 
       function (callback) {
         const params = {
-          name: video.name,
           remoteId: video.id
         }
 
@@ -249,6 +247,14 @@ function associate (models) {
     through: models.VideoTag,
     onDelete: 'cascade'
   })
+
+  this.hasMany(models.VideoAbuse, {
+    foreignKey: {
+      name: 'videoId',
+      allowNull: false
+    },
+    onDelete: 'cascade'
+  })
 }
 
 function generateMagnetUri () {
@@ -329,7 +335,8 @@ function toFormatedJSON () {
     duration: this.duration,
     tags: map(this.Tags, 'name'),
     thumbnailPath: constants.STATIC_PATHS.THUMBNAILS + '/' + this.getThumbnailName(),
-    createdAt: this.createdAt
+    createdAt: this.createdAt,
+    updatedAt: this.updatedAt
   }
 
   return json
@@ -356,6 +363,7 @@ function toAddRemoteJSON (callback) {
       thumbnailData: thumbnailData.toString('binary'),
       tags: map(self.Tags, 'name'),
       createdAt: self.createdAt,
+      updatedAt: self.updatedAt,
       extname: self.extname
     }
 
@@ -373,6 +381,7 @@ function toUpdateRemoteJSON (callback) {
     duration: this.duration,
     tags: map(this.Tags, 'name'),
     createdAt: this.createdAt,
+    updatedAt: this.updatedAt,
     extname: this.extname
   }
 
@@ -428,7 +437,7 @@ function listForApi (start, count, sort, callback) {
   })
 }
 
-function listByHostAndRemoteId (fromHost, remoteId, callback) {
+function loadByHostAndRemoteId (fromHost, remoteId, callback) {
   const query = {
     where: {
       remoteId: remoteId
@@ -449,7 +458,7 @@ function listByHostAndRemoteId (fromHost, remoteId, callback) {
     ]
   }
 
-  return this.findAll(query).asCallback(callback)
+  return this.findOne(query).asCallback(callback)
 }
 
 function listOwnedAndPopulateAuthorAndTags (callback) {