]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/accounts.ts
Merge branch 'release/3.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / controllers / api / accounts.ts
index 05740318efe046d40f26f0bda41dca059b747cf7..e31924a9410b5d87acfccf3d45a9aeedb954daff 100644 (file)
@@ -1,5 +1,9 @@
 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 { Hooks } from '../../lib/plugins/hooks'
+import { JobQueue } from '../../lib/job-queue'
 import {
   asyncMiddleware,
   authenticate,
@@ -8,6 +12,7 @@ import {
   paginationValidator,
   setDefaultPagination,
   setDefaultSort,
+  setDefaultVideosSort,
   videoPlaylistsSortValidator,
   videoRatesSortValidator,
   videoRatingValidator
@@ -16,21 +21,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 +51,7 @@ accountsRouter.get('/:accountName/videos',
   asyncMiddleware(accountNameWithHostGetValidator),
   paginationValidator,
   videosSortValidator,
-  setDefaultSort,
+  setDefaultVideosSort,
   setDefaultPagination,
   optionalAuthenticate,
   commonVideosFiltersValidator,
@@ -60,6 +60,7 @@ accountsRouter.get('/:accountName/videos',
 
 accountsRouter.get('/:accountName/video-channels',
   asyncMiddleware(accountNameWithHostGetValidator),
+  videoChannelStatsValidator,
   paginationValidator,
   videoChannelsSortValidator,
   setDefaultSort,
@@ -104,7 +105,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 +121,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)
@@ -157,7 +159,7 @@ async function listAccountVideos (req: express.Request, res: express.Response) {
   const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
   const countVideos = getCountVideos(req)
 
-  const resultList = await VideoModel.listForApi({
+  const apiOptions = await Hooks.wrapObject({
     followerActorId,
     start: req.query.start,
     count: req.query.count,
@@ -173,8 +175,15 @@ async function listAccountVideos (req: express.Request, res: express.Response) {
     withFiles: false,
     accountId: account.id,
     user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
-    countVideos
-  })
+    countVideos,
+    search: req.query.search
+  }, 'filter:api.accounts.videos.list.params')
+
+  const resultList = await Hooks.wrapPromiseFun(
+    VideoModel.listForApi,
+    apiOptions,
+    'filter:api.accounts.videos.list.result'
+  )
 
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }