]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/accounts.ts
Add pagination to account video channels endpoint
[github/Chocobozzz/PeerTube.git] / server / controllers / api / accounts.ts
index aa01ea1ebb0b966bd4b45bd210843928eca1bbe6..9b3489120521b60bc38a91c79483aabea9e88edd 100644 (file)
@@ -1,22 +1,23 @@
 import * as express from 'express'
 import { getFormattedObjects, getServerActor } from '../../helpers/utils'
 import {
-  authenticate,
   asyncMiddleware,
+  authenticate,
   commonVideosFiltersValidator,
-  videoRatingValidator,
   optionalAuthenticate,
   paginationValidator,
   setDefaultPagination,
   setDefaultSort,
   videoPlaylistsSortValidator,
-  videoRatesSortValidator
+  videoRatesSortValidator,
+  videoRatingValidator
 } from '../../middlewares'
 import {
   accountNameWithHostGetValidator,
   accountsSortValidator,
+  ensureAuthUserOwnsAccountValidator,
   videosSortValidator,
-  ensureAuthUserOwnsAccountValidator
+  videoChannelsSortValidator
 } from '../../middlewares/validators'
 import { AccountModel } from '../../models/account/account'
 import { AccountVideoRateModel } from '../../models/account/account-video-rate'
@@ -56,6 +57,10 @@ accountsRouter.get('/:accountName/videos',
 
 accountsRouter.get('/:accountName/video-channels',
   asyncMiddleware(accountNameWithHostGetValidator),
+  paginationValidator,
+  videoChannelsSortValidator,
+  setDefaultSort,
+  setDefaultPagination,
   asyncMiddleware(listAccountChannels)
 )
 
@@ -108,7 +113,14 @@ async function listAccounts (req: express.Request, res: express.Response) {
 }
 
 async function listAccountChannels (req: express.Request, res: express.Response) {
-  const resultList = await VideoChannelModel.listByAccount(res.locals.account.id)
+  const options = {
+    accountId: res.locals.account.id,
+    start: req.query.start,
+    count: req.query.count,
+    sort: req.query.sort,
+  }
+
+  const resultList = await VideoChannelModel.listByAccount(options)
 
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }