Client: add views information and sort
[oweals/peertube.git] / server / models / video.js
index 742150d69e3f59fd58f996978f715c7c2c6ca882..daa273845f5610de2b90f85df4a405a2cda2cb59 100644 (file)
@@ -80,6 +80,15 @@ module.exports = function (sequelize, DataTypes) {
             if (res === false) throw new Error('Video duration is not valid.')
           }
         }
+      },
+      views: {
+        type: DataTypes.INTEGER,
+        allowNull: false,
+        defaultValue: 0,
+        validate: {
+          min: 0,
+          isInt: true
+        }
       }
     },
     {
@@ -101,6 +110,9 @@ module.exports = function (sequelize, DataTypes) {
         },
         {
           fields: [ 'infoHash' ]
+        },
+        {
+          fields: [ 'views' ]
         }
       ],
       classMethods: {
@@ -336,6 +348,7 @@ function toFormatedJSON () {
     magnetUri: this.generateMagnetUri(),
     author: this.Author.name,
     duration: this.duration,
+    views: this.views,
     tags: map(this.Tags, 'name'),
     thumbnailPath: pathUtils.join(constants.STATIC_PATHS.THUMBNAILS, this.getThumbnailName()),
     createdAt: this.createdAt,
@@ -414,7 +427,7 @@ function getDurationFromFile (videoPath, callback) {
 }
 
 function list (callback) {
-  return this.find().asCallback()
+  return this.findAll().asCallback(callback)
 }
 
 function listForApi (start, count, sort, callback) {