diff options
-rw-r--r-- | server/controllers/api/server/stats.ts | 4 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test/main.js | 7 | ||||
-rw-r--r-- | server/tests/plugins/external-auth.ts | 2 | ||||
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 10 | ||||
-rw-r--r-- | shared/models/plugins/server/server-hook.model.ts | 3 |
5 files changed, 24 insertions, 2 deletions
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index d661144ca..2ab398f4d 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts | |||
@@ -3,6 +3,7 @@ import { StatsManager } from '@server/lib/stat-manager' | |||
3 | import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' | 3 | import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' |
4 | import { asyncMiddleware } from '../../../middlewares' | 4 | import { asyncMiddleware } from '../../../middlewares' |
5 | import { cacheRoute } from '../../../middlewares/cache/cache' | 5 | import { cacheRoute } from '../../../middlewares/cache/cache' |
6 | import { Hooks } from '@server/lib/plugins/hooks' | ||
6 | 7 | ||
7 | const statsRouter = express.Router() | 8 | const statsRouter = express.Router() |
8 | 9 | ||
@@ -12,7 +13,8 @@ statsRouter.get('/stats', | |||
12 | ) | 13 | ) |
13 | 14 | ||
14 | async function getStats (_req: express.Request, res: express.Response) { | 15 | async function getStats (_req: express.Request, res: express.Response) { |
15 | const data = await StatsManager.Instance.getStats() | 16 | let data = await StatsManager.Instance.getStats() |
17 | data = await Hooks.wrapObject(data, 'filter:api.server.stats.get.result') | ||
16 | 18 | ||
17 | return res.json(data) | 19 | return res.json(data) |
18 | } | 20 | } |
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index db405ff31..aba415d1e 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js | |||
@@ -233,6 +233,13 @@ async function register ({ registerHook, registerSetting, settingsManager, stora | |||
233 | } | 233 | } |
234 | }) | 234 | }) |
235 | 235 | ||
236 | registerHook({ | ||
237 | target: 'filter:api.server.stats.get.result', | ||
238 | handler: (result) => { | ||
239 | return { ...result, customStats: 14 } | ||
240 | } | ||
241 | }) | ||
242 | |||
236 | { | 243 | { |
237 | const filterHooks = [ | 244 | const filterHooks = [ |
238 | 'filter:api.search.videos.local.list.params', | 245 | 'filter:api.search.videos.local.list.params', |
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index f3e018d43..25b25bfee 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts | |||
@@ -125,7 +125,7 @@ describe('Test external auth plugins', function () { | |||
125 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | 125 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
126 | }) | 126 | }) |
127 | 127 | ||
128 | await server.servers.waitUntilLog('expired external auth token', 2) | 128 | await server.servers.waitUntilLog('expired external auth token', 4) |
129 | }) | 129 | }) |
130 | 130 | ||
131 | it('Should auto login Cyan, create the user and use the token', async function () { | 131 | it('Should auto login Cyan, create the user and use the token', async function () { |
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 02915f08c..80014566b 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -537,6 +537,16 @@ describe('Test plugin filter hooks', function () { | |||
537 | }) | 537 | }) |
538 | }) | 538 | }) |
539 | 539 | ||
540 | describe('Stats filters', function () { | ||
541 | |||
542 | it('Should run filter:api.server.stats.get.result', async function () { | ||
543 | const data = await servers[0].stats.get() | ||
544 | |||
545 | expect((data as any).customStats).to.equal(14) | ||
546 | }) | ||
547 | |||
548 | }) | ||
549 | |||
540 | after(async function () { | 550 | after(async function () { |
541 | await cleanupTests(servers) | 551 | await cleanupTests(servers) |
542 | }) | 552 | }) |
diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts index 3ab910197..7e344e003 100644 --- a/shared/models/plugins/server/server-hook.model.ts +++ b/shared/models/plugins/server/server-hook.model.ts | |||
@@ -63,6 +63,9 @@ export const serverFilterHookObject = { | |||
63 | 'filter:api.video-thread-comments.list.params': true, | 63 | 'filter:api.video-thread-comments.list.params': true, |
64 | 'filter:api.video-thread-comments.list.result': true, | 64 | 'filter:api.video-thread-comments.list.result': true, |
65 | 65 | ||
66 | // Filter get stats result | ||
67 | 'filter:api.server.stats.get.result': true, | ||
68 | |||
66 | // Filter result used to check if we need to auto blacklist a video | 69 | // Filter result used to check if we need to auto blacklist a video |
67 | // (fired when a local or remote video is created or updated) | 70 | // (fired when a local or remote video is created or updated) |
68 | 'filter:video.auto-blacklist.result': true, | 71 | 'filter:video.auto-blacklist.result': true, |