]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/feeds.ts
Move test functions outside extra-utils
[github/Chocobozzz/PeerTube.git] / server / controllers / feeds.ts
index f0717bbbca62dd3b7e55ad58a4dd85d8f6bd1731..29502a15458d8fd91aba60b893a5dd5e32f0bab4 100644 (file)
@@ -1,6 +1,8 @@
-import * as express from 'express'
-import * as Feed from 'pfeed'
-import { VideoFilter } from '../../shared/models/videos/video-query.type'
+import express from 'express'
+import Feed from 'pfeed'
+import { getServerActor } from '@server/models/application/application'
+import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils'
+import { VideoInclude } from '@shared/models'
 import { buildNSFWFilter } from '../helpers/express-utils'
 import { CONFIG } from '../initializers/config'
 import { FEEDS, PREVIEWS_SIZE, ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants'
@@ -15,20 +17,20 @@ import {
   videosSortValidator,
   videoSubscriptionFeedsValidator
 } from '../middlewares'
-import { cacheRoute } from '../middlewares/cache'
+import { cacheRouteFactory } from '../middlewares/cache/cache'
 import { VideoModel } from '../models/video/video'
 import { VideoCommentModel } from '../models/video/video-comment'
 
 const feedsRouter = express.Router()
 
+const cacheRoute = cacheRouteFactory({
+  headerBlacklist: [ 'Content-Type' ]
+})
+
 feedsRouter.get('/feeds/video-comments.:format',
   feedsFormatValidator,
   setFeedFormatContentType,
-  asyncMiddleware(cacheRoute({
-    headerBlacklist: [
-      'Content-Type'
-    ]
-  })(ROUTE_CACHE_LIFETIME.FEEDS)),
+  cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS),
   asyncMiddleware(videoFeedsValidator),
   asyncMiddleware(videoCommentsFeedsValidator),
   asyncMiddleware(generateVideoCommentsFeed)
@@ -39,11 +41,7 @@ feedsRouter.get('/feeds/videos.:format',
   setDefaultVideosSort,
   feedsFormatValidator,
   setFeedFormatContentType,
-  asyncMiddleware(cacheRoute({
-    headerBlacklist: [
-      'Content-Type'
-    ]
-  })(ROUTE_CACHE_LIFETIME.FEEDS)),
+  cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS),
   commonVideosFiltersValidator,
   asyncMiddleware(videoFeedsValidator),
   asyncMiddleware(generateVideoFeed)
@@ -54,11 +52,7 @@ feedsRouter.get('/feeds/subscriptions.:format',
   setDefaultVideosSort,
   feedsFormatValidator,
   setFeedFormatContentType,
-  asyncMiddleware(cacheRoute({
-    headerBlacklist: [
-      'Content-Type'
-    ]
-  })(ROUTE_CACHE_LIFETIME.FEEDS)),
+  cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS),
   commonVideosFiltersValidator,
   asyncMiddleware(videoSubscriptionFeedsValidator),
   asyncMiddleware(generateVideoFeedForSubscriptions)
@@ -167,14 +161,19 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
     videoChannelId: videoChannel ? videoChannel.id : null
   }
 
+  const server = await getServerActor()
   const { data } = await VideoModel.listForApi({
     start,
     count: FEEDS.COUNT,
     sort: req.query.sort,
-    includeLocalVideos: true,
+    displayOnlyForFollower: {
+      actorId: server.id,
+      orLocalVideos: true
+    },
     nsfw,
-    filter: req.query.filter as VideoFilter,
-    withFiles: true,
+    isLocal: req.query.isLocal,
+    include: req.query.include | VideoInclude.FILES,
+    hasFiles: true,
     countVideos: false,
     ...options
   })
@@ -203,14 +202,19 @@ async function generateVideoFeedForSubscriptions (req: express.Request, res: exp
     start,
     count: FEEDS.COUNT,
     sort: req.query.sort,
-    includeLocalVideos: false,
     nsfw,
-    filter: req.query.filter as VideoFilter,
 
-    withFiles: true,
+    isLocal: req.query.isLocal,
+
+    hasFiles: true,
+    include: req.query.include | VideoInclude.FILES,
+
     countVideos: false,
 
-    followerActorId: res.locals.user.Account.Actor.id,
+    displayOnlyForFollower: {
+      actorId: res.locals.user.Account.Actor.id,
+      orLocalVideos: false
+    },
     user: res.locals.user
   })
 
@@ -286,14 +290,14 @@ function addVideosToFeed (feed, videos: VideoModel[]) {
     if (video.category) {
       categories.push({
         value: video.category,
-        label: VideoModel.getCategoryLabel(video.category)
+        label: getCategoryLabel(video.category)
       })
     }
 
     feed.addItem({
       title: video.name,
       id: video.url,
-      link: WEBSERVER.URL + '/videos/watch/' + video.uuid,
+      link: WEBSERVER.URL + video.getWatchStaticPath(),
       description: video.getTruncatedDescription(),
       content: video.description,
       author: [