aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/overviews.ts
diff options
context:
space:
mode:
authorMichael Williams <michael.williams@enspiral.com>2021-06-27 02:22:48 +1200
committerChocobozzz <me@florianbigard.com>2021-07-21 16:01:34 +0200
commit64f9b91de99eb04cad12ec7370eddc30f6fda1e5 (patch)
tree2bfb5d3d1bb851ee1261f3f7ce2e7af37d224524 /server/controllers/api/overviews.ts
parente19fdf5775aa43fcc766308cbc4dcd66a5d0776e (diff)
downloadPeerTube-64f9b91de99eb04cad12ec7370eddc30f6fda1e5.tar.gz
PeerTube-64f9b91de99eb04cad12ec7370eddc30f6fda1e5.tar.zst
PeerTube-64f9b91de99eb04cad12ec7370eddc30f6fda1e5.zip
Add new filter hooks to /overviews/videos
This change adds new filter hooks `filter:api.overviews.videos.list.params` and `filter:api.overviews.videos.list.params` to /overviews/videos. The motivation is to make a plugin to [use `originallyPublishedAt` in all places where `publishedAt` is used](https://github.com/ahdinosaur/peertube-plugin-originally-published-at).
Diffstat (limited to 'server/controllers/api/overviews.ts')
-rw-r--r--server/controllers/api/overviews.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/server/controllers/api/overviews.ts b/server/controllers/api/overviews.ts
index aaa341d54..727ed66d7 100644
--- a/server/controllers/api/overviews.ts
+++ b/server/controllers/api/overviews.ts
@@ -1,12 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as memoizee from 'memoizee' 2import * as memoizee from 'memoizee'
3import { logger } from '@server/helpers/logger' 3import { logger } from '@server/helpers/logger'
4import { Hooks } from '@server/lib/plugins/hooks'
5import { VideoModel } from '@server/models/video/video'
4import { CategoryOverview, ChannelOverview, TagOverview, VideosOverview } from '../../../shared/models/overviews' 6import { CategoryOverview, ChannelOverview, TagOverview, VideosOverview } from '../../../shared/models/overviews'
5import { buildNSFWFilter } from '../../helpers/express-utils' 7import { buildNSFWFilter } from '../../helpers/express-utils'
6import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants' 8import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants'
7import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares' 9import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares'
8import { TagModel } from '../../models/video/tag' 10import { TagModel } from '../../models/video/tag'
9import { VideoModel } from '../../models/video/video'
10 11
11const overviewsRouter = express.Router() 12const overviewsRouter = express.Router()
12 13
@@ -108,7 +109,7 @@ async function getVideos (
108 res: express.Response, 109 res: express.Response,
109 where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] } 110 where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] }
110) { 111) {
111 const query = Object.assign({ 112 let query = Object.assign({
112 start: 0, 113 start: 0,
113 count: 12, 114 count: 12,
114 sort: '-createdAt', 115 sort: '-createdAt',
@@ -119,7 +120,13 @@ async function getVideos (
119 countVideos: false 120 countVideos: false
120 }, where) 121 }, where)
121 122
122 const { data } = await VideoModel.listForApi(query) 123 query = await Hooks.wrapObject(query, 'filter:api.overviews.videos.list.params')
124
125 const { data } = await Hooks.wrapPromiseFun(
126 VideoModel.listForApi,
127 query,
128 'filter:api.overviews.videos.list.result'
129 )
123 130
124 return data.map(d => d.toFormattedJSON()) 131 return data.map(d => d.toFormattedJSON())
125} 132}