]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video.js
Server: fix update remote video
[github/Chocobozzz/PeerTube.git] / server / models / video.js
index f51d08f06f4a4e430c9cbb811d881af6c80e4e78..17eff64288ab1d4916fcd7105bf1c267b4389003 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: {
@@ -142,7 +141,8 @@ module.exports = function (sequelize, DataTypes) {
 }
 
 function beforeValidate (video, options, next) {
-  if (video.isOwned()) {
+  // Put a fake infoHash if it does not exists yet
+  if (video.isOwned() && !video.infoHash) {
     // 40 hexa length
     video.infoHash = '0123456789abcdef0123456789abcdef01234567'
   }
@@ -219,7 +219,6 @@ function afterDestroy (video, options, next) {
 
       function (callback) {
         const params = {
-          name: video.name,
           remoteId: video.id
         }
 
@@ -249,6 +248,14 @@ function associate (models) {
     through: models.VideoTag,
     onDelete: 'cascade'
   })
+
+  this.hasMany(models.VideoAbuse, {
+    foreignKey: {
+      name: 'videoId',
+      allowNull: false
+    },
+    onDelete: 'cascade'
+  })
 }
 
 function generateMagnetUri () {
@@ -328,8 +335,9 @@ function toFormatedJSON () {
     author: this.Author.name,
     duration: this.duration,
     tags: map(this.Tags, 'name'),
-    thumbnailPath: constants.STATIC_PATHS.THUMBNAILS + '/' + this.getThumbnailName(),
-    createdAt: this.createdAt
+    thumbnailPath: pathUtils.join(constants.STATIC_PATHS.THUMBNAILS, this.getThumbnailName()),
+    createdAt: this.createdAt,
+    updatedAt: this.updatedAt
   }
 
   return json
@@ -356,6 +364,7 @@ function toAddRemoteJSON (callback) {
       thumbnailData: thumbnailData.toString('binary'),
       tags: map(self.Tags, 'name'),
       createdAt: self.createdAt,
+      updatedAt: self.updatedAt,
       extname: self.extname
     }
 
@@ -373,6 +382,7 @@ function toUpdateRemoteJSON (callback) {
     duration: this.duration,
     tags: map(this.Tags, 'name'),
     createdAt: this.createdAt,
+    updatedAt: this.updatedAt,
     extname: this.extname
   }