From 64f9b91de99eb04cad12ec7370eddc30f6fda1e5 Mon Sep 17 00:00:00 2001 From: Michael Williams Date: Sun, 27 Jun 2021 02:22:48 +1200 Subject: 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). --- server/controllers/api/overviews.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'server/controllers') 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()) } -- cgit v1.2.3