]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/accounts.ts
Optimize default sort when listing videos
[github/Chocobozzz/PeerTube.git] / server / controllers / api / accounts.ts
index 00148ff555a7dd0282ff30fb7fcbf14c77edc8ef..0a73dfcbf258eafa5c7a1d9d9793ecc442266657 100644 (file)
@@ -1,5 +1,8 @@
 import * as express from 'express'
-import { getFormattedObjects, getServerActor } from '../../helpers/utils'
+import { getServerActor } from '@server/models/application/application'
+import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
+import { getFormattedObjects } from '../../helpers/utils'
+import { JobQueue } from '../../lib/job-queue'
 import {
   asyncMiddleware,
   authenticate,
@@ -8,6 +11,7 @@ import {
   paginationValidator,
   setDefaultPagination,
   setDefaultSort,
+  setDefaultVideosSort,
   videoPlaylistsSortValidator,
   videoRatesSortValidator,
   videoRatingValidator
@@ -16,21 +20,16 @@ import {
   accountNameWithHostGetValidator,
   accountsSortValidator,
   ensureAuthUserOwnsAccountValidator,
-  videosSortValidator,
-  videoChannelsSortValidator
+  videoChannelsSortValidator,
+  videoChannelStatsValidator,
+  videosSortValidator
 } from '../../middlewares/validators'
+import { commonVideoPlaylistFiltersValidator, videoPlaylistsSearchValidator } from '../../middlewares/validators/videos/video-playlists'
 import { AccountModel } from '../../models/account/account'
 import { AccountVideoRateModel } from '../../models/account/account-video-rate'
 import { VideoModel } from '../../models/video/video'
-import { buildNSFWFilter, isUserAbleToSearchRemoteURI, getCountVideos } from '../../helpers/express-utils'
 import { VideoChannelModel } from '../../models/video/video-channel'
-import { JobQueue } from '../../lib/job-queue'
-import { logger } from '../../helpers/logger'
 import { VideoPlaylistModel } from '../../models/video/video-playlist'
-import {
-  commonVideoPlaylistFiltersValidator,
-  videoPlaylistsSearchValidator
-} from '../../middlewares/validators/videos/video-playlists'
 
 const accountsRouter = express.Router()
 
@@ -51,7 +50,7 @@ accountsRouter.get('/:accountName/videos',
   asyncMiddleware(accountNameWithHostGetValidator),
   paginationValidator,
   videosSortValidator,
-  setDefaultSort,
+  setDefaultVideosSort,
   setDefaultPagination,
   optionalAuthenticate,
   commonVideosFiltersValidator,
@@ -60,6 +59,7 @@ accountsRouter.get('/:accountName/videos',
 
 accountsRouter.get('/:accountName/video-channels',
   asyncMiddleware(accountNameWithHostGetValidator),
+  videoChannelStatsValidator,
   paginationValidator,
   videoChannelsSortValidator,
   setDefaultSort,
@@ -104,7 +104,6 @@ function getAccount (req: express.Request, res: express.Response) {
 
   if (account.isOutdated()) {
     JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: account.Actor.url } })
-            .catch(err => logger.error('Cannot create AP refresher job for actor %s.', account.Actor.url, { err }))
   }
 
   return res.json(account.toFormattedJSON())
@@ -121,7 +120,9 @@ async function listAccountChannels (req: express.Request, res: express.Response)
     accountId: res.locals.account.id,
     start: req.query.start,
     count: req.query.count,
-    sort: req.query.sort
+    sort: req.query.sort,
+    withStats: req.query.withStats,
+    search: req.query.search
   }
 
   const resultList = await VideoChannelModel.listByAccount(options)
@@ -133,9 +134,9 @@ async function listAccountPlaylists (req: express.Request, res: express.Response
   const serverActor = await getServerActor()
 
   // Allow users to see their private/unlisted video playlists
-  let privateAndUnlisted = false
+  let listMyPlaylists = false
   if (res.locals.oauth && res.locals.oauth.token.User.Account.id === res.locals.account.id) {
-    privateAndUnlisted = true
+    listMyPlaylists = true
   }
 
   const resultList = await VideoPlaylistModel.listForApi({
@@ -145,7 +146,7 @@ async function listAccountPlaylists (req: express.Request, res: express.Response
     count: req.query.count,
     sort: req.query.sort,
     accountId: res.locals.account.id,
-    privateAndUnlisted,
+    listMyPlaylists,
     type: req.query.playlistType
   })