Server: little refractoring when listing videos
authorChocobozzz <florian.bigard@gmail.com>
Mon, 1 May 2017 17:09:55 +0000 (19:09 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 1 May 2017 17:24:37 +0000 (19:24 +0200)
server/models/video.js

index 0eef4114c724e1e2cdcda4330b0517c7c99c9ac1..029cb6d7cd040fb5b7e71940153d23304a558f6a 100644 (file)
@@ -544,11 +544,7 @@ function listForApi (start, count, sort, callback) {
 
       this.sequelize.models.Tag
     ],
-    where: {
-      id: { $notIn: this.sequelize.literal(
-        '(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")'
-      )}
-    }
+    where: createBaseVideosWhere.call(this)
   }
 
   return this.findAndCountAll(query).asCallback(function (err, result) {
@@ -656,11 +652,7 @@ function searchAndPopulateAuthorAndPodAndTags (value, field, start, count, sort,
   }
 
   const query = {
-    where: {
-      id: { $notIn: this.sequelize.literal(
-        '(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")'
-      )}
-    },
+    where: createBaseVideosWhere.call(this),
     offset: start,
     limit: count,
     distinct: true, // For the count, a video can have many tags
@@ -715,6 +707,16 @@ function searchAndPopulateAuthorAndPodAndTags (value, field, start, count, sort,
 
 // ---------------------------------------------------------------------------
 
+function createBaseVideosWhere () {
+  return {
+    id: {
+      $notIn: this.sequelize.literal(
+        '(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")'
+      )
+    }
+  }
+}
+
 function removeThumbnail (video, callback) {
   const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
   fs.unlink(thumbnailPath, callback)