diff options
author | Michael Williams <michael.williams@enspiral.com> | 2021-06-27 02:22:48 +1200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 16:01:34 +0200 |
commit | 64f9b91de99eb04cad12ec7370eddc30f6fda1e5 (patch) | |
tree | 2bfb5d3d1bb851ee1261f3f7ce2e7af37d224524 /server | |
parent | e19fdf5775aa43fcc766308cbc4dcd66a5d0776e (diff) | |
download | PeerTube-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')
-rw-r--r-- | server/controllers/api/overviews.ts | 13 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as memoizee from 'memoizee' | 2 | import * as memoizee from 'memoizee' |
3 | import { logger } from '@server/helpers/logger' | 3 | import { logger } from '@server/helpers/logger' |
4 | import { Hooks } from '@server/lib/plugins/hooks' | ||
5 | import { VideoModel } from '@server/models/video/video' | ||
4 | import { CategoryOverview, ChannelOverview, TagOverview, VideosOverview } from '../../../shared/models/overviews' | 6 | import { CategoryOverview, ChannelOverview, TagOverview, VideosOverview } from '../../../shared/models/overviews' |
5 | import { buildNSFWFilter } from '../../helpers/express-utils' | 7 | import { buildNSFWFilter } from '../../helpers/express-utils' |
6 | import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants' | 8 | import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants' |
7 | import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares' | 9 | import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares' |
8 | import { TagModel } from '../../models/video/tag' | 10 | import { TagModel } from '../../models/video/tag' |
9 | import { VideoModel } from '../../models/video/video' | ||
10 | 11 | ||
11 | const overviewsRouter = express.Router() | 12 | const 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 | } |