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 @@ import * as express from 'express' import * as memoizee from 'memoizee' import { logger } from '@server/helpers/logger' +import { Hooks } from '@server/lib/plugins/hooks' +import { VideoModel } from '@server/models/video/video' import { CategoryOverview, ChannelOverview, TagOverview, VideosOverview } from '../../../shared/models/overviews' import { buildNSFWFilter } from '../../helpers/express-utils' import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants' import { asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares' import { TagModel } from '../../models/video/tag' -import { VideoModel } from '../../models/video/video' const overviewsRouter = express.Router() @@ -108,7 +109,7 @@ async function getVideos ( res: express.Response, where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] } ) { - const query = Object.assign({ + let query = Object.assign({ start: 0, count: 12, sort: '-createdAt', @@ -119,7 +120,13 @@ async function getVideos ( countVideos: false }, where) - const { data } = await VideoModel.listForApi(query) + query = await Hooks.wrapObject(query, 'filter:api.overviews.videos.list.params') + + const { data } = await Hooks.wrapPromiseFun( + VideoModel.listForApi, + query, + 'filter:api.overviews.videos.list.result' + ) return data.map(d => d.toFormattedJSON()) } diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts index 5f29534b5..562c6eb12 100644 --- a/shared/models/plugins/server/server-hook.model.ts +++ b/shared/models/plugins/server/server-hook.model.ts @@ -18,6 +18,10 @@ export const serverFilterHookObject = { 'filter:api.user.me.videos.list.params': true, 'filter:api.user.me.videos.list.result': true, + // Filter params/result used to list overview videos for the REST API + 'filter:api.overviews.videos.list.params': true, + 'filter:api.overviews.videos.list.result': true, + // Filter params/results to search videos/channels in the DB or on the remote index 'filter:api.search.videos.local.list.params': true, 'filter:api.search.videos.local.list.result': true,