]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/feeds.ts
Fix account link in the menu
[github/Chocobozzz/PeerTube.git] / server / controllers / feeds.ts
index 700c50ec8ac9a3260649687bc88614f968c80c5b..08f179509e1747bcfb83207e2fa3f0a515747799 100644 (file)
@@ -1,16 +1,11 @@
 import * as express from 'express'
-import { CONFIG } from '../initializers'
-import {
-  asyncMiddleware,
-  feedsValidator,
-  setDefaultPagination,
-  setDefaultSort,
-  videosSortValidator
-} from '../middlewares'
+import { CONFIG, FEEDS } from '../initializers/constants'
+import { asyncMiddleware, feedsValidator, setDefaultSort, videosSortValidator } from '../middlewares'
 import { VideoModel } from '../models/video/video'
 import * as Feed from 'pfeed'
-import { ResultList } from '../../shared/models'
 import { AccountModel } from '../models/account/account'
+import { cacheRoute } from '../middlewares/cache'
+import { VideoChannelModel } from '../models/video/video-channel'
 
 const feedsRouter = express.Router()
 
@@ -18,6 +13,7 @@ feedsRouter.get('/feeds/videos.:format',
   videosSortValidator,
   setDefaultSort,
   asyncMiddleware(feedsValidator),
+  asyncMiddleware(cacheRoute),
   asyncMiddleware(generateFeed)
 )
 
@@ -31,29 +27,22 @@ export {
 
 async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
   let feed = initFeed()
-  const paginationStart = 0
-  const paginationCount = 20
+  const start = 0
 
-  let resultList: ResultList<VideoModel>
   const account: AccountModel = res.locals.account
-
-  if (account) {
-    resultList = await VideoModel.listAccountVideosForApi(
-      account.id,
-      paginationStart,
-      paginationCount,
-      req.query.sort,
-      true
-    )
-  } else {
-    resultList = await VideoModel.listForApi(
-      paginationStart,
-      paginationCount,
-      req.query.sort,
-      req.query.filter,
-      true
-    )
-  }
+  const videoChannel: VideoChannelModel = res.locals.videoChannel
+  const hideNSFW = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list'
+
+  const resultList = await VideoModel.listForApi({
+    start,
+    count: FEEDS.COUNT,
+    sort: req.query.sort,
+    hideNSFW,
+    filter: req.query.filter,
+    withFiles: true,
+    accountId: account ? account.id : null,
+    videoChannelId: videoChannel ? videoChannel.id : null
+  })
 
   // Adding video items to the feed, one at a time
   resultList.data.forEach(video => {