Clearer feed controller
authorChocobozzz <me@florianbigard.com>
Mon, 9 Dec 2019 08:40:16 +0000 (09:40 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 9 Dec 2019 09:23:22 +0000 (10:23 +0100)
server/controllers/feeds.ts

index 6b64ff22720be688d1132b604bab92a71a168ad8..104fd5dd97508007746276c6949da5efbf825c1a 100644 (file)
@@ -113,22 +113,36 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
   // Adding video items to the feed, one at a time
   resultList.data.forEach(video => {
     const formattedVideoFiles = video.getFormattedVideoFilesJSON()
+
     const torrents = formattedVideoFiles.map(videoFile => ({
       title: video.name,
       url: videoFile.torrentUrl,
       size_in_bytes: videoFile.size
     }))
-    const videos = formattedVideoFiles.map(videoFile => (Object.assign({
-      type: 'video/mp4',
-      medium: 'video',
-      height: videoFile.resolution.label.replace('p', ''),
-      fileSize: videoFile.size,
-      url: videoFile.fileUrl,
-      framerate: videoFile.fps,
-      duration: video.duration
-    }, video.language ? {
-      lang: video.language
-    } : {})))
+
+    const videos = formattedVideoFiles.map(videoFile => {
+      const result = {
+        type: 'video/mp4',
+        medium: 'video',
+        height: videoFile.resolution.label.replace('p', ''),
+        fileSize: videoFile.size,
+        url: videoFile.fileUrl,
+        framerate: videoFile.fps,
+        duration: video.duration
+      }
+
+      if (video.language) Object.assign(result, { lang: video.language })
+
+      return result
+    })
+
+    const categories: { value: number, label: string }[] = []
+    if (video.category) {
+      categories.push({
+        value: video.category,
+        label: VideoModel.getCategoryLabel(video.category)
+      })
+    }
 
     feed.addItem({
       title: video.name,
@@ -153,10 +167,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
       player: {
         url: video.getWatchStaticPath()
       },
-      categories: [video.category ? {
-        value: video.category,
-        label: VideoModel.getCategoryLabel(video.category)
-      } : null].filter(Boolean),
+      categories,
       community: {
         statistics: {
           views: video.views